Compare commits
1 Commits
notificati
...
notificati
| Author | SHA1 | Date | |
|---|---|---|---|
| 54611ef812 |
@@ -21,7 +21,7 @@ export default {
|
|||||||
"Aplikasi membutuhkan akses lokasi untuk menampilkan peta.",
|
"Aplikasi membutuhkan akses lokasi untuk menampilkan peta.",
|
||||||
},
|
},
|
||||||
associatedDomains: ["applinks:cld-dkr-staging-hipmi.wibudev.com"],
|
associatedDomains: ["applinks:cld-dkr-staging-hipmi.wibudev.com"],
|
||||||
buildNumber: "16",
|
buildNumber: "17",
|
||||||
},
|
},
|
||||||
|
|
||||||
android: {
|
android: {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { ButtonCustom, StackCustom, ViewWrapper } from "@/components";
|
import { ButtonCustom, StackCustom, ViewWrapper } from "@/components";
|
||||||
import { MainColor } from "@/constants/color-palet";
|
import { MainColor } from "@/constants/color-palet";
|
||||||
import { useAuth } from "@/hooks/use-auth";
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
|
import { useNotificationStore } from "@/hooks/use-notification-store";
|
||||||
import Home_BottomFeatureSection from "@/screens/Home/bottomFeatureSection";
|
import Home_BottomFeatureSection from "@/screens/Home/bottomFeatureSection";
|
||||||
import HeaderBell from "@/screens/Home/HeaderBell";
|
import HeaderBell from "@/screens/Home/HeaderBell";
|
||||||
import Home_ImageSection from "@/screens/Home/imageSection";
|
import Home_ImageSection from "@/screens/Home/imageSection";
|
||||||
@@ -20,12 +21,16 @@ export default function Application() {
|
|||||||
const { token, user, userData } = useAuth();
|
const { token, user, userData } = useAuth();
|
||||||
const [data, setData] = useState<any>();
|
const [data, setData] = useState<any>();
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
|
const { syncUnreadCount } = useNotificationStore();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
onLoadData();
|
onLoadData();
|
||||||
checkVersion();
|
checkVersion();
|
||||||
userData(token as string);
|
userData(token as string);
|
||||||
|
syncUnreadCount()
|
||||||
}, [user?.id, token])
|
}, [user?.id, token])
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -98,9 +103,9 @@ export default function Application() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<StackCustom>
|
<StackCustom>
|
||||||
{/* <ButtonCustom onPress={() => router.push("./test-notifications")}>
|
<ButtonCustom onPress={() => router.push("./test-notifications")}>
|
||||||
Test Notif
|
Test Notif
|
||||||
</ButtonCustom> */}
|
</ButtonCustom>
|
||||||
|
|
||||||
<Home_ImageSection />
|
<Home_ImageSection />
|
||||||
|
|
||||||
|
|||||||
@@ -5,36 +5,26 @@ import {
|
|||||||
TextInputCustom,
|
TextInputCustom,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import { useAuth } from "@/hooks/use-auth";
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
import { apiGetAllTokenDevice } from "@/service/api-device-token";
|
|
||||||
import { apiNotificationsSend } from "@/service/api-notifications";
|
import { apiNotificationsSend } from "@/service/api-notifications";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function TestNotification() {
|
export default function TestNotification() {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const [data, setData] = useState("");
|
const [data, setData] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// fecthData();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const fecthData = async () => {
|
|
||||||
const response = await apiGetAllTokenDevice();
|
|
||||||
console.log(
|
|
||||||
"[RES GET ALL TOKEN DEVICE]",
|
|
||||||
JSON.stringify(response.data, null, 2)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
console.log("[Data Dikirim]", data);
|
console.log("[Data Dikirim]", data);
|
||||||
const response = await apiNotificationsSend({
|
const response = await apiNotificationsSend({
|
||||||
data: {
|
data: {
|
||||||
fcmToken:
|
|
||||||
"cVmHm-3P4E-1vjt6AA9kSF:APA91bHTkHjGTLxrFsb6Le6bZmzboZhwMGYXU4p0FP9yEeXixLDXNKS4F5vLuZV3sRgSnjjQsPpLOgstVLHJB8VJTObctKLdN-CxAp4dnP7Jbc_mH53jWvs",
|
|
||||||
title: "Test dari Backend (App Router)!",
|
title: "Test dari Backend (App Router)!",
|
||||||
body: data,
|
body: data,
|
||||||
userLoginId: user?.id || "",
|
userLoginId: user?.id || "",
|
||||||
|
appId: "hipmi",
|
||||||
|
status: "publish",
|
||||||
|
kategoriApp: "EVENT",
|
||||||
|
type: "announcement",
|
||||||
|
deepLink: "event/23189913801",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
ICON_SIZE_XLARGE,
|
ICON_SIZE_XLARGE,
|
||||||
} from "@/constants/constans-value";
|
} from "@/constants/constans-value";
|
||||||
import { useAuth } from "@/hooks/use-auth";
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
|
import AdminNotificationBell from "@/screens/Admin/AdminNotificationBell";
|
||||||
import {
|
import {
|
||||||
adminListMenu,
|
adminListMenu,
|
||||||
superAdminListMenu,
|
superAdminListMenu,
|
||||||
@@ -192,11 +193,12 @@ export default function AdminLayout() {
|
|||||||
label: "Notifikasi",
|
label: "Notifikasi",
|
||||||
value: "notification",
|
value: "notification",
|
||||||
icon: (
|
icon: (
|
||||||
<Ionicons
|
// <Ionicons
|
||||||
name="notifications"
|
// name="notifications"
|
||||||
size={ICON_SIZE_SMALL}
|
// size={ICON_SIZE_SMALL}
|
||||||
color={MainColor.white}
|
// color={MainColor.white}
|
||||||
/>
|
// />
|
||||||
|
<AdminNotificationBell/>
|
||||||
),
|
),
|
||||||
path: "/admin/notification",
|
path: "/admin/notification",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import NotificationInitializer from "@/components/Notification/NotificationInitializer";
|
|
||||||
import { AuthProvider } from "@/context/AuthContext";
|
import { AuthProvider } from "@/context/AuthContext";
|
||||||
import { NotificationProvider } from "@/hooks/use-notification-store";
|
|
||||||
import AppRoot from "@/screens/RootLayout/AppRoot";
|
import AppRoot from "@/screens/RootLayout/AppRoot";
|
||||||
import "react-native-gesture-handler";
|
import "react-native-gesture-handler";
|
||||||
import { SafeAreaProvider } from "react-native-safe-area-context";
|
import { SafeAreaProvider } from "react-native-safe-area-context";
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export default function NotificationInitializer() {
|
|||||||
if (!supported) {
|
if (!supported) {
|
||||||
console.log("‼️ FCM tidak didukung");
|
console.log("‼️ FCM tidak didukung");
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
const authStatus = await requestPermission(messagingInstance);
|
const authStatus = await requestPermission(messagingInstance);
|
||||||
if (authStatus !== AuthorizationStatus.AUTHORIZED) {
|
if (authStatus !== AuthorizationStatus.AUTHORIZED) {
|
||||||
@@ -62,7 +62,7 @@ export default function NotificationInitializer() {
|
|||||||
"-" +
|
"-" +
|
||||||
(Application.nativeBuildVersion || "unknown");
|
(Application.nativeBuildVersion || "unknown");
|
||||||
const deviceId =
|
const deviceId =
|
||||||
Device.osInternalBuildId || Device.modelName + "-" + Date.now();
|
Device.osInternalBuildId || Device.modelName || "unknown";
|
||||||
|
|
||||||
// Kirim ke backend
|
// Kirim ke backend
|
||||||
await apiDeviceRegisterToken({
|
await apiDeviceRegisterToken({
|
||||||
@@ -101,7 +101,7 @@ export default function NotificationInitializer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log("📥 Menambahkan ke store:", { title, body, safeData });
|
console.log("📥 Menambahkan ke store:", { title, body, safeData });
|
||||||
addNotification({ title, body, data: safeData , type: "notification", });
|
addNotification({ title, body, data: safeData, type: "notification" });
|
||||||
console.log("✅ Notifikasi ditambahkan ke state");
|
console.log("✅ Notifikasi ditambahkan ke state");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
|
|||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, useEffect, useState } from "react";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
|
import * as Device from "expo-device";
|
||||||
|
|
||||||
// --- Types ---
|
// --- Types ---
|
||||||
type AuthContextType = {
|
type AuthContextType = {
|
||||||
@@ -77,7 +78,6 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
const response = await apiLogin({ nomor: nomor });
|
const response = await apiLogin({ nomor: nomor });
|
||||||
console.log("[RESPONSE AUTH]", JSON.stringify(response));
|
console.log("[RESPONSE AUTH]", JSON.stringify(response));
|
||||||
|
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
console.log("[Keluar provider]", nomor);
|
console.log("[Keluar provider]", nomor);
|
||||||
Toast.show({
|
Toast.show({
|
||||||
@@ -148,7 +148,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
router.replace("/(application)/(user)/home");
|
router.replace("/(application)/(user)/home");
|
||||||
return
|
return;
|
||||||
} else {
|
} else {
|
||||||
router.replace("/(application)/(user)/waiting-room");
|
router.replace("/(application)/(user)/waiting-room");
|
||||||
return;
|
return;
|
||||||
@@ -283,9 +283,12 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setToken(null);
|
setToken(null);
|
||||||
setUser(null);
|
setUser(null);
|
||||||
|
|
||||||
|
const deviceId = Device.osInternalBuildId || Device.modelName || "unknown";
|
||||||
|
|
||||||
await AsyncStorage.removeItem("authToken");
|
await AsyncStorage.removeItem("authToken");
|
||||||
await AsyncStorage.removeItem("userData");
|
await AsyncStorage.removeItem("userData");
|
||||||
await apiDeviceTokenDeleted({userId: user?.id as any})
|
await apiDeviceTokenDeleted({ userId: user?.id as any, deviceId });
|
||||||
|
|
||||||
Toast.show({
|
Toast.show({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export const NotificationProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
try {
|
try {
|
||||||
const count = await apiNotificationUnreadCount({
|
const count = await apiNotificationUnreadCount({
|
||||||
id: user?.id as any,
|
id: user?.id as any,
|
||||||
|
role: user?.masterUserRoleId as any
|
||||||
}); // ← harus return number
|
}); // ← harus return number
|
||||||
const result = count.data;
|
const result = count.data;
|
||||||
console.log("📖 Unread count:", result);
|
console.log("📖 Unread count:", result);
|
||||||
@@ -105,8 +106,10 @@ export const NotificationProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
try {
|
try {
|
||||||
const count = await apiNotificationUnreadCount({
|
const count = await apiNotificationUnreadCount({
|
||||||
id: user?.id as any,
|
id: user?.id as any,
|
||||||
|
role: user?.masterUserRoleId as any,
|
||||||
}); // ← harus return number
|
}); // ← harus return number
|
||||||
const result = count.data;
|
const result = count.data;
|
||||||
|
console.log("📖 Unread count sync:", result);
|
||||||
setUnreadCount(result);
|
setUnreadCount(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("⚠️ Gagal sync unread count:", error);
|
console.warn("⚠️ Gagal sync unread count:", error);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>16</string>
|
<string>17</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
41
screens/Admin/AdminNotificationBell.tsx
Normal file
41
screens/Admin/AdminNotificationBell.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// components/HeaderBell.tsx
|
||||||
|
import { MainColor } from "@/constants/color-palet";
|
||||||
|
import { ICON_SIZE_SMALL } from "@/constants/constans-value";
|
||||||
|
import { useNotificationStore } from "@/hooks/use-notification-store";
|
||||||
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
import { router } from "expo-router";
|
||||||
|
import { Text, View } from "react-native";
|
||||||
|
|
||||||
|
export default function AdminNotificationBell() {
|
||||||
|
const { unreadCount } = useNotificationStore();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={{ position: "relative" }}>
|
||||||
|
<Ionicons
|
||||||
|
name="notifications"
|
||||||
|
size={ICON_SIZE_SMALL}
|
||||||
|
color={MainColor.white}
|
||||||
|
/>
|
||||||
|
{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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
// components/HeaderBell.tsx
|
// components/HeaderBell.tsx
|
||||||
import { MainColor } from "@/constants/color-palet";
|
import { MainColor } from "@/constants/color-palet";
|
||||||
|
import { useAuth } from "@/hooks/use-auth";
|
||||||
import { useNotificationStore } from "@/hooks/use-notification-store";
|
import { useNotificationStore } from "@/hooks/use-notification-store";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { useEffect } from "react";
|
|
||||||
import { Text, View } from "react-native";
|
import { Text, View } from "react-native";
|
||||||
|
|
||||||
export default function HeaderBell() {
|
export default function HeaderBell() {
|
||||||
const { notifications , unreadCount} = useNotificationStore();
|
const { unreadCount } = useNotificationStore();
|
||||||
// console.log("NOTIF:", JSON.stringify(notifications, null, 2));
|
const { user } = useAuth();
|
||||||
|
|
||||||
|
const pathDetector =
|
||||||
|
user?.masterUserRoleId === "1" ? "/notifications" : "/admin/notification";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ position: "relative" }}>
|
<View style={{ position: "relative" }}>
|
||||||
@@ -17,7 +20,7 @@ export default function HeaderBell() {
|
|||||||
size={20}
|
size={20}
|
||||||
color={MainColor.yellow}
|
color={MainColor.yellow}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
router.push("/notifications");
|
router.push(pathDetector);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{unreadCount > 0 && (
|
{unreadCount > 0 && (
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ export async function apiDeviceRegisterToken({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiDeviceTokenDeleted({ userId }: { userId: string }) {
|
export async function apiDeviceTokenDeleted({ userId, deviceId }: { userId: string, deviceId: string }) {
|
||||||
try {
|
try {
|
||||||
const response = await apiConfig.delete(
|
const response = await apiConfig.delete(
|
||||||
`/mobile/auth/device-tokens/${userId}`
|
`/mobile/auth/device-tokens/${userId}?deviceId=${deviceId}`
|
||||||
);
|
);
|
||||||
console.log("Device token deleted:", response.data);
|
console.log("Device token deleted:", response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
import { apiConfig } from "./api-config";
|
import { apiConfig } from "./api-config";
|
||||||
|
|
||||||
type NotificationProp = {
|
type NotificationProp = {
|
||||||
fcmToken: string;
|
|
||||||
title: string;
|
title: string;
|
||||||
body: Object;
|
body: string;
|
||||||
userLoginId?: string;
|
userLoginId: string;
|
||||||
|
appId?: string;
|
||||||
|
status?: string;
|
||||||
|
type?: "announcement" | "trigger";
|
||||||
|
deepLink?: string;
|
||||||
|
kategoriApp?:
|
||||||
|
| "JOB"
|
||||||
|
| "VOTING"
|
||||||
|
| "EVENT"
|
||||||
|
| "DONASI"
|
||||||
|
| "INVESTASI"
|
||||||
|
| "COLLABORATION"
|
||||||
|
| "FORUM"
|
||||||
|
| "ACCESS"; // Untuk trigger akses user;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function apiNotificationsSend({
|
export async function apiNotificationsSend({
|
||||||
@@ -44,11 +56,13 @@ export async function apiGetNotificationsById({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiNotificationUnreadCount({ id }: { id: string }) {
|
export async function apiNotificationUnreadCount({ id, role }: { id: string, role: "user" | "admin" }) {
|
||||||
try {
|
try {
|
||||||
const response = await apiConfig.get(
|
const response = await apiConfig.get(
|
||||||
`/mobile/notification/${id}/unread-count`
|
`/mobile/notification/${id}/unread-count?role=${role}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log("Response Unread Count", response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user