Percobaan notifikasi
Add: - app/(application)/(user)/test-notifications.tsx - components/_ShareComponent/NotificationInitializer.tsx - screens/Home/HeaderBell.tsx - service/api-notifications.ts Fix: - app/(application)/(user)/home.tsx - app/_layout.tsx - screens/Authentication/LoginView.tsx ### No Issue
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import { StackCustom, ViewWrapper } from "@/components";
|
||||
import { ButtonCustom, StackCustom, ViewWrapper } from "@/components";
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useNotificationStore } from "@/hooks/use-notification-store";
|
||||
import Home_BottomFeatureSection from "@/screens/Home/bottomFeatureSection";
|
||||
import HeaderBell from "@/screens/Home/HeaderBell";
|
||||
import Home_ImageSection from "@/screens/Home/imageSection";
|
||||
import TabSection from "@/screens/Home/tabSection";
|
||||
import { tabsHome } from "@/screens/Home/tabsList";
|
||||
@@ -22,12 +23,11 @@ export default function Application() {
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
// console.log("[User] >>", JSON.stringify(user?.id, null, 2));
|
||||
|
||||
const { notifications } = useNotificationStore();
|
||||
const unreadCount = notifications.filter((n) => !n.read).length;
|
||||
|
||||
console.log("UNREAD", unreadCount)
|
||||
|
||||
// const { notifications } = useNotificationStore();
|
||||
// const unreadCount = notifications.filter((n) => !n.read).length;
|
||||
// console.log("UNREAD", notifications)
|
||||
// ‼️ Untuk cek apakah: 1. user ada, 2. user punya profile, 3. accept temrs of forum nya ada atau tidak
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
onLoadData();
|
||||
@@ -88,46 +88,47 @@ export default function Application() {
|
||||
}}
|
||||
/>
|
||||
),
|
||||
headerRight: () => {
|
||||
return (
|
||||
<View style={{ position: "relative" }}>
|
||||
<Ionicons
|
||||
name="notifications"
|
||||
size={20}
|
||||
color={MainColor.yellow}
|
||||
onPress={() => {
|
||||
router.push("/notifications");
|
||||
}}
|
||||
/>
|
||||
{unreadCount > 0 && (
|
||||
<View
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: -4,
|
||||
right: -4,
|
||||
backgroundColor: "red",
|
||||
borderRadius: 8,
|
||||
minWidth: 16,
|
||||
height: 16,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
paddingHorizontal: 2,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: "white",
|
||||
fontSize: 10,
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
>
|
||||
{unreadCount > 9 ? "9+" : unreadCount}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
},
|
||||
headerRight: () => <HeaderBell />,
|
||||
// headerRight: () => {
|
||||
// return (
|
||||
// <View style={{ position: "relative" }}>
|
||||
// <Ionicons
|
||||
// name="notifications"
|
||||
// size={20}
|
||||
// color={MainColor.yellow}
|
||||
// onPress={() => {
|
||||
// router.push("/notifications");
|
||||
// }}
|
||||
// />
|
||||
// {unreadCount > 0 && (
|
||||
// <View
|
||||
// style={{
|
||||
// position: "absolute",
|
||||
// top: -4,
|
||||
// right: -4,
|
||||
// backgroundColor: "red",
|
||||
// borderRadius: 8,
|
||||
// minWidth: 16,
|
||||
// height: 16,
|
||||
// justifyContent: "center",
|
||||
// alignItems: "center",
|
||||
// paddingHorizontal: 2,
|
||||
// }}
|
||||
// >
|
||||
// <Text
|
||||
// style={{
|
||||
// color: "white",
|
||||
// fontSize: 10,
|
||||
// fontWeight: "bold",
|
||||
// }}
|
||||
// >
|
||||
// {unreadCount > 9 ? "9+" : unreadCount}
|
||||
// </Text>
|
||||
// </View>
|
||||
// )}
|
||||
// </View>
|
||||
// );
|
||||
// },
|
||||
}}
|
||||
/>
|
||||
<ViewWrapper
|
||||
@@ -144,6 +145,8 @@ export default function Application() {
|
||||
}
|
||||
>
|
||||
<StackCustom>
|
||||
<ButtonCustom onPress={() => router.push("./test-notifications")}>Test Notif</ButtonCustom>
|
||||
|
||||
<Home_ImageSection />
|
||||
|
||||
<Home_FeatureSection />
|
||||
|
||||
48
app/(application)/(user)/test-notifications.tsx
Normal file
48
app/(application)/(user)/test-notifications.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
ButtonCustom,
|
||||
NewWrapper,
|
||||
StackCustom,
|
||||
TextInputCustom,
|
||||
} from "@/components";
|
||||
import { apiNotificationsSend } from "@/service/api-notifications";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function TestNotification() {
|
||||
const [data, setData] = useState("");
|
||||
const handleSubmit = async () => {
|
||||
console.log("[Data Dikirim]", data);
|
||||
const response = await apiNotificationsSend({
|
||||
data: {
|
||||
fcmToken:
|
||||
"cVmHm-3P4E-1vjt6AA9kSF:APA91bHTkHjGTLxrFsb6Le6bZmzboZhwMGYXU4p0FP9yEeXixLDXNKS4F5vLuZV3sRgSnjjQsPpLOgstVLHJB8VJTObctKLdN-CxAp4dnP7Jbc_mH53jWvs",
|
||||
title: "Test dari Backend (App Router)!",
|
||||
body: data,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[RES SEND NOTIF]", JSON.stringify(response.data, null, 2));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<NewWrapper>
|
||||
<StackCustom>
|
||||
<TextInputCustom
|
||||
required
|
||||
label="Nama"
|
||||
placeholder="Masukkan nama"
|
||||
value={data}
|
||||
onChangeText={(text) => setData(text)}
|
||||
/>
|
||||
<ButtonCustom
|
||||
onPress={() => {
|
||||
handleSubmit();
|
||||
}}
|
||||
>
|
||||
Kirim
|
||||
</ButtonCustom>
|
||||
</StackCustom>
|
||||
</NewWrapper>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user