Compare commits
11 Commits
mobile-not
...
mobile-not
| Author | SHA1 | Date | |
|---|---|---|---|
| d50fda90e0 | |||
| d3d4912a5f | |||
| b2e8bc3caf | |||
| f05571caa4 | |||
| 6507bdcd35 | |||
| e2c8a1edbc | |||
| 02b25ffc84 | |||
| 3e0d2743fb | |||
| fc3ee6724e | |||
| a72cf866fa | |||
| c50e0ceaf7 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -2,6 +2,16 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.5.31](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.30...v1.5.31) (2025-12-24)
|
||||
|
||||
## [1.5.30](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.29...v1.5.30) (2025-12-19)
|
||||
|
||||
## [1.5.29](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.28...v1.5.29) (2025-12-17)
|
||||
|
||||
## [1.5.28](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.27...v1.5.28) (2025-12-17)
|
||||
|
||||
## [1.5.27](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.26...v1.5.27) (2025-12-17)
|
||||
|
||||
## [1.5.26](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.25...v1.5.26) (2025-12-10)
|
||||
|
||||
## [1.5.25](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.24...v1.5.25) (2025-12-09)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.26",
|
||||
"version": "1.5.31",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Donasi_Invoice" ALTER COLUMN "masterBankId" DROP DEFAULT;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Notifikasi" ADD COLUMN "type" TEXT;
|
||||
@@ -0,0 +1,16 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Notifikasi" DROP CONSTRAINT "Notifikasi_userRoleId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Notifikasi" ADD COLUMN "recipientId" TEXT,
|
||||
ADD COLUMN "senderId" TEXT,
|
||||
ALTER COLUMN "userRoleId" DROP NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Notifikasi" ADD CONSTRAINT "Notifikasi_userRoleId_fkey" FOREIGN KEY ("userRoleId") REFERENCES "MasterUserRole"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Notifikasi" ADD CONSTRAINT "Notifikasi_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Notifikasi" ADD CONSTRAINT "Notifikasi_senderId_fkey" FOREIGN KEY ("senderId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -59,6 +59,10 @@ model User {
|
||||
acceptedTermsAt DateTime?
|
||||
acceptedForumTermsAt DateTime?
|
||||
tokenUserDevices TokenUserDevice[]
|
||||
|
||||
// For Mobile App
|
||||
NotificationRecipient Notifikasi[] @relation("NotificationRecipient")
|
||||
NotificationSender Notifikasi[] @relation("NotificationSender")
|
||||
}
|
||||
|
||||
model MasterUserRole {
|
||||
@@ -587,7 +591,7 @@ model Donasi_Invoice {
|
||||
|
||||
imageId String?
|
||||
MasterBank MasterBank? @relation(fields: [masterBankId], references: [id])
|
||||
masterBankId String? @default("null")
|
||||
masterBankId String?
|
||||
}
|
||||
|
||||
model Donasi_Kabar {
|
||||
@@ -974,27 +978,36 @@ model NomorAdmin {
|
||||
}
|
||||
|
||||
model Notifikasi {
|
||||
id String @id @default(cuid())
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
appId String
|
||||
kategoriApp String
|
||||
pesan String
|
||||
title String?
|
||||
status String?
|
||||
|
||||
isRead Boolean @default(false)
|
||||
readAt DateTime? // kapan user membaca notifikasi ini
|
||||
deepLink String? // misal: "announcement/123", "user/profile/cmha6wb9w0001cfndwl9fcse6"
|
||||
|
||||
isRead Boolean @default(false)
|
||||
readAt DateTime? // kapan user membaca notifikasi ini
|
||||
deepLink String? // misal: "announcement/123", "user/profile/cmha6wb9w0001cfndwl9fcse6"
|
||||
type String?
|
||||
|
||||
Role MasterUserRole? @relation(fields: [userRoleId], references: [id])
|
||||
userRoleId String
|
||||
userRoleId String?
|
||||
|
||||
User User? @relation("UserNotifikasi", fields: [userId], references: [id], map: "NotifikasiUser")
|
||||
userId String?
|
||||
Admin User? @relation("AdminNotifikasi", fields: [adminId], references: [id], map: "NotifikasiAdmin")
|
||||
adminId String?
|
||||
|
||||
// Recipient (user who receives the notification)
|
||||
recipient User? @relation("NotificationRecipient", fields: [recipientId], references: [id])
|
||||
recipientId String?
|
||||
|
||||
// Sender (user who sent the notification)
|
||||
sender User? @relation("NotificationSender", fields: [senderId], references: [id])
|
||||
senderId String?
|
||||
}
|
||||
|
||||
// MAPS
|
||||
|
||||
@@ -33,18 +33,24 @@ export async function POST(req: Request) {
|
||||
// const encodedMsg = encodeURIComponent(msg);
|
||||
|
||||
const res = await fetch(
|
||||
`https://wa.wibudev.com/code?nom=${nomor}&text=${msg}`,
|
||||
{ cache: "no-cache" }
|
||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${msg}`,
|
||||
{
|
||||
cache: "no-cache",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const sendWa = await res.json();
|
||||
|
||||
if (sendWa.status !== "success")
|
||||
if (res.status !== 200)
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
const sendWa = await res.text();
|
||||
console.log("WA Response:", sendWa);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
@@ -63,5 +69,5 @@ export async function POST(req: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,25 @@ export async function POST(req: Request) {
|
||||
|
||||
const msg = `HIPMI%20-%20Kode%20ini%20bersifat%20RAHASIA%20dan%20JANGAN%20DI%20BAGIKAN%20KEPADA%20SIAPAPUN%2C%20termasuk%20anggota%20ataupun%20pengurus%20HIPMI%20lainnya.%5Cn%5Cn%3E%3E%20Kode%20OTP%20anda%3A%20${codeOtp}.`;
|
||||
|
||||
const res = await fetch(
|
||||
`https://wa.wibudev.com/code?nom=${nomor}&text=${msg}`,
|
||||
{ cache: "no-cache" }
|
||||
const res = await fetch(
|
||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${msg}`,
|
||||
{
|
||||
cache: "no-cache",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const sendWa = await res.json();
|
||||
|
||||
if (sendWa.status !== "success")
|
||||
if (res.status !== 200)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Nomor Whatsapp Tidak Aktif",
|
||||
},
|
||||
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
const sendWa = await res.text();
|
||||
console.log("WA Response:", sendWa);
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
data: {
|
||||
nomor: nomor,
|
||||
|
||||
51
src/app/api/mobile/auth/device-tokens/[id]/route.ts
Normal file
51
src/app/api/mobile/auth/device-tokens/[id]/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export { DELETE };
|
||||
|
||||
async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const deviceId = searchParams.get("deviceId");
|
||||
|
||||
console.log("ID", id);
|
||||
console.log("DEVICE ID", deviceId);
|
||||
|
||||
try {
|
||||
const findFirst = await prisma.tokenUserDevice.findFirst({
|
||||
where: {
|
||||
userId: id,
|
||||
deviceId: deviceId as any,
|
||||
},
|
||||
});
|
||||
|
||||
if (!findFirst) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "User tidak ditemukan !",
|
||||
});
|
||||
}
|
||||
|
||||
const deleted = await prisma.tokenUserDevice.delete({
|
||||
where: {
|
||||
id: findFirst.id,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("DEL", deleted);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil menghapus device token user",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("ERROR", error);
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message, message: "Terjadi error pada API" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
export { POST, GET };
|
||||
|
||||
async function POST(request: NextRequest) {
|
||||
const { data } = await request.json();
|
||||
try {
|
||||
console.log("Data >>", JSON.stringify(data, null, 2));
|
||||
|
||||
const { userId, platform, deviceId, model, appVersion, fcmToken } =
|
||||
data;
|
||||
const { userId, platform, deviceId, model, appVersion, fcmToken } = data;
|
||||
|
||||
if (!fcmToken) {
|
||||
return NextResponse.json({ error: "Missing Token" }, { status: 400 });
|
||||
@@ -23,6 +23,9 @@ export async function POST(request: NextRequest) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
console.log("✅ EX", existing);
|
||||
|
||||
let deviceToken;
|
||||
|
||||
if (existing) {
|
||||
@@ -62,3 +65,22 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function GET(request: NextRequest) {
|
||||
try {
|
||||
const data = await prisma.tokenUserDevice.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, data });
|
||||
|
||||
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
67
src/app/api/mobile/notification/[id]/route.ts
Normal file
67
src/app/api/mobile/notification/[id]/route.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
let fixData;
|
||||
const fixCategory = _.upperCase(category || "");
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
await prisma.notifikasi.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
isRead: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notifications marked as read",
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
31
src/app/api/mobile/notification/[id]/unread-count/route.ts
Normal file
31
src/app/api/mobile/notification/[id]/unread-count/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
console.log("User ID:", id);
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.count({
|
||||
where: {
|
||||
recipientId: id,
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("List Notification >>", data);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed to get unread count",
|
||||
});
|
||||
}
|
||||
}
|
||||
180
src/app/api/mobile/notification/route.ts
Normal file
180
src/app/api/mobile/notification/route.ts
Normal file
@@ -0,0 +1,180 @@
|
||||
// app/api/test/notifications/route.ts
|
||||
import { prisma } from "@/lib";
|
||||
import { adminMessaging } from "@/lib/firebase-admin";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
type NotificationProp = {
|
||||
title: string;
|
||||
body: string;
|
||||
userLoginId: string;
|
||||
appId?: string;
|
||||
status?: string;
|
||||
kategoriApp?: string;
|
||||
type?: string;
|
||||
deepLink?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { data } = await request.json();
|
||||
|
||||
const {
|
||||
title,
|
||||
body: notificationBody,
|
||||
userLoginId,
|
||||
type,
|
||||
kategoriApp,
|
||||
appId,
|
||||
status,
|
||||
deepLink,
|
||||
} = data as NotificationProp;
|
||||
|
||||
console.log("Notification Send >>", data);
|
||||
|
||||
// Cari user yang login
|
||||
const findUserLogin = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userLoginId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!findUserLogin) {
|
||||
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
// Cari token fcm user yang login
|
||||
const checkFcmToken = await prisma.tokenUserDevice.findFirst({
|
||||
where: {
|
||||
userId: findUserLogin.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!checkFcmToken) {
|
||||
return NextResponse.json(
|
||||
{ error: "FCM Token not found" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Jika user yang masuk maka notifikasik akan dikirim ke semua admin , begitu sebaliknya !
|
||||
const filterByCurrentLoginId =
|
||||
findUserLogin.masterUserRoleId === "1" ? "2" : "1";
|
||||
|
||||
// Cari user yang akan menerima notifikasi
|
||||
const findAllUserBySendTo = await prisma.user.findMany({
|
||||
where: {
|
||||
masterUserRoleId: filterByCurrentLoginId,
|
||||
NOT: {
|
||||
id: findUserLogin.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Find All User By Send To >>", findAllUserBySendTo);
|
||||
|
||||
for (let a of findAllUserBySendTo) {
|
||||
const responseCreatedNotifications = await createNotification({
|
||||
title,
|
||||
type: type as string,
|
||||
createdAt: new Date(),
|
||||
pesan: notificationBody || "",
|
||||
appId: appId as string,
|
||||
kategoriApp: kategoriApp as string,
|
||||
userRoleId: findUserLogin.masterUserRoleId,
|
||||
status: status,
|
||||
deepLink: deepLink,
|
||||
senderId: findUserLogin.id,
|
||||
recipientId: a.id,
|
||||
});
|
||||
|
||||
if (responseCreatedNotifications) {
|
||||
const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
where: {
|
||||
userId: a.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of deviceToken) {
|
||||
const message = {
|
||||
token: i.token,
|
||||
notification: {
|
||||
title,
|
||||
body: notificationBody || "",
|
||||
},
|
||||
data: {
|
||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
id: responseCreatedNotifications.id,
|
||||
deepLink: deepLink || "",
|
||||
// contoh: senderId, type, etc.
|
||||
},
|
||||
};
|
||||
|
||||
const response = await adminMessaging.send(message);
|
||||
console.log("✅ FCM sent:", response);
|
||||
}
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed to create notification",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notification sent successfully",
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("❌ FCM error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || "Failed to send FCM" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createNotification({
|
||||
title,
|
||||
type,
|
||||
createdAt,
|
||||
appId,
|
||||
kategoriApp,
|
||||
pesan,
|
||||
userRoleId,
|
||||
status,
|
||||
deepLink,
|
||||
senderId,
|
||||
recipientId,
|
||||
}: {
|
||||
title: string;
|
||||
type: string;
|
||||
createdAt: Date;
|
||||
appId: string;
|
||||
kategoriApp: string;
|
||||
userRoleId: string;
|
||||
status?: string;
|
||||
deepLink?: string;
|
||||
pesan: string;
|
||||
|
||||
senderId: string;
|
||||
recipientId: string;
|
||||
}) {
|
||||
const createNotification = await prisma.notifikasi.create({
|
||||
data: {
|
||||
title,
|
||||
type,
|
||||
createdAt,
|
||||
appId,
|
||||
kategoriApp,
|
||||
pesan,
|
||||
userRoleId,
|
||||
status,
|
||||
deepLink,
|
||||
senderId,
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
return createNotification;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// app/api/test/notifications/route.ts
|
||||
import { adminMessaging } from "@/lib/firebase-admin";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { data } = await request.json();
|
||||
const { fcmToken, title, body: notificationBody } = data;
|
||||
|
||||
console.log("Data Notifikasi >>", data);
|
||||
|
||||
if (!fcmToken || !title) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing fcmToken or title" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const message = {
|
||||
token: fcmToken,
|
||||
notification: {
|
||||
title,
|
||||
body: notificationBody || "",
|
||||
},
|
||||
data: {
|
||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
// contoh: senderId, type, etc.
|
||||
},
|
||||
};
|
||||
|
||||
console.log("[MSG]", message);
|
||||
|
||||
const response = await adminMessaging.send(message);
|
||||
console.log("✅ FCM sent:", response);
|
||||
|
||||
return NextResponse.json({ success: true, messageId: response });
|
||||
} catch (error: any) {
|
||||
console.error("❌ FCM error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || "Failed to send FCM" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,24 @@ import { apiFetchLogin } from "../_lib/api_fetch_auth";
|
||||
|
||||
export default function Login({ version }: { version: string }) {
|
||||
const router = useRouter();
|
||||
const [phone, setPhone] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isError, setError] = useState(false);
|
||||
|
||||
const [phone, setPhone] = useState("");
|
||||
const [countryCode, setCountryCode] = useState<string>("62"); // default ke Indonesia
|
||||
|
||||
async function onLogin() {
|
||||
const nomor = phone.substring(1);
|
||||
console.log("phone >>", phone);
|
||||
|
||||
const nomor = phone;
|
||||
if (nomor.length <= 4) return setError(true);
|
||||
|
||||
const fixPhone = `${countryCode}${nomor}`;
|
||||
console.log("fixPhone >>", fixPhone);
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const respone = await apiFetchLogin({ nomor: nomor });
|
||||
const respone = await apiFetchLogin({ nomor: fixPhone });
|
||||
|
||||
if (respone && respone.success) {
|
||||
localStorage.setItem("hipmi_auth_code_id", respone.kodeId);
|
||||
@@ -72,16 +79,38 @@ export default function Login({ version }: { version: string }) {
|
||||
<Center>
|
||||
<Text c={MainColor.white}>Nomor telepon</Text>
|
||||
</Center>
|
||||
|
||||
<PhoneInput
|
||||
countrySelectorStyleProps={{
|
||||
buttonStyle: {
|
||||
backgroundColor: MainColor.login,
|
||||
},
|
||||
}}
|
||||
inputStyle={{ width: "100%", backgroundColor: MainColor.login }}
|
||||
defaultCountry="id"
|
||||
onChange={(val) => {
|
||||
setPhone(val);
|
||||
inputStyle={{ width: "100%", backgroundColor: MainColor.login }}
|
||||
onChange={(fullPhone, meta) => {
|
||||
const dialCode = meta.country.dialCode; // string, misal: "62"
|
||||
let localNumber = fullPhone;
|
||||
|
||||
// Hapus kode negara dari awal string
|
||||
if (fullPhone.startsWith(`+${dialCode}`)) {
|
||||
localNumber = fullPhone.slice(`+${dialCode}`.length);
|
||||
}
|
||||
|
||||
// Bersihkan semua non-digit
|
||||
localNumber = localNumber.replace(/\D/g, "");
|
||||
|
||||
// ✅ Filter khusus: untuk Indonesia (+62), hapus leading zero
|
||||
if (dialCode === "62" && localNumber.startsWith("0")) {
|
||||
localNumber = localNumber.replace(/^0+/, ""); // hapus semua 0 di awal
|
||||
}
|
||||
|
||||
// Simpan hasil akhir
|
||||
setCountryCode(dialCode);
|
||||
setPhone(localNumber);
|
||||
|
||||
// console.log("Country Code:", dialCode);
|
||||
// console.log("Clean Local Number:", localNumber);
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
7
x.sh
7
x.sh
@@ -3,10 +3,13 @@ URL="http://localhost:3000"
|
||||
# curl -X GET -H "Authorization: Bearer $TOKEN" ${URL}/api/middleware
|
||||
# curl -X GET -H "Cookie: hipmi-key=$TOKEN; user_id=789" ${URL}/dev/home | tee test.html
|
||||
|
||||
curl -X POST ${URL}/api/mobile/notifications \
|
||||
curl -X POST ${URL}/api/mobile/notification \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"fcmToken": "cVmHm-3P4E-1vjt6AA9kSF:APA91bHTkHjGTLxrFsb6Le6bZmzboZhwMGYXU4p0FP9yEeXixLDXNKS4F5vLuZV3sRgSnjjQsPpLOgstVLHJB8VJTObctKLdN-CxAp4dnP7Jbc_mH53jWvs",
|
||||
"title": "Test dari Backend (App Router)!",
|
||||
"body": "Berhasil di App Router!"
|
||||
"body": "Berhasil di App Router!",
|
||||
"userLoginId": "cmha7p6yc0000cfoe5w2e7gdr",
|
||||
"type": "NOTIFICATION",
|
||||
"kategoriApp": "PERCOBAAN"
|
||||
}'
|
||||
Reference in New Issue
Block a user