fix admin
deskripsi: - fix api nomor admin
This commit is contained in:
32
src/app/api/master/admin-contact/route.ts
Normal file
32
src/app/api/master/admin-contact/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const data = await prisma.nomorAdmin.findFirst({
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get admin contact",
|
||||
data: data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get admin contact", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get admin contact",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,12 @@ import adminAppInformation_getNomorAdmin from "@/app_modules/admin/app_info/fun/
|
||||
import { AdminAppInformation_UiMain } from "@/app_modules/admin/app_info/ui";
|
||||
|
||||
export default async function Page() {
|
||||
const nomorAdmin = await adminAppInformation_getNomorAdmin();
|
||||
const listBank = await adminAppInformation_getMasterBank();
|
||||
const dataBidangBisnis = await adminAppInformation_funGetBidangBisnis()
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminAppInformation_UiMain
|
||||
nomorAdmin={nomorAdmin}
|
||||
listBank={listBank}
|
||||
dataBidangBisnis={dataBidangBisnis}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
export { apiGetMasterBank, apiGetMasterBidangBisnis, apiGetMasterStatusTransaksi };
|
||||
export {
|
||||
apiGetMasterBank,
|
||||
apiGetMasterBidangBisnis,
|
||||
apiGetMasterStatusTransaksi,
|
||||
apiGetAdminContact,
|
||||
};
|
||||
|
||||
const apiGetMasterBank = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
@@ -37,14 +42,51 @@ const apiGetMasterStatusTransaksi = async () => {
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/master/status_transaksi`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
}
|
||||
})
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
};
|
||||
|
||||
const apiGetAdminContact = async () => {
|
||||
try {
|
||||
// Fetch token from cookie
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) {
|
||||
console.error("No token found");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Send PUT request to update portfolio logo
|
||||
const response = await fetch(`/api/master/admin-contact`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
// Check if the response is OK
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
console.error(
|
||||
"Error get admin contact:",
|
||||
errorData?.message || "Unknown error"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error get admin contact:", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,15 +7,23 @@ export default async function adminAppInformation_funUpdateNomorAdmin({
|
||||
}: {
|
||||
data: any;
|
||||
}) {
|
||||
const updt = await prisma.nomorAdmin.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
nomor: data.nomor,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const updt = await prisma.nomorAdmin.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
nomor: data.nomor,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updt) return { status: 400, message: "Gagal update" };
|
||||
return { status: 200, message: "Berhasil update" };
|
||||
if (!updt) return { status: 400, message: "Gagal update" };
|
||||
return { status: 200, message: "Berhasil update" };
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 500,
|
||||
message: "Error update",
|
||||
error: (error as Error).message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,9 @@ import {
|
||||
import { AccentColor, AdminColor, MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
|
||||
export default function AdminAppInformation_UiMain({
|
||||
nomorAdmin,
|
||||
listBank,
|
||||
dataBidangBisnis,
|
||||
}: {
|
||||
nomorAdmin: any;
|
||||
listBank: any[];
|
||||
dataBidangBisnis: any[];
|
||||
}) {
|
||||
@@ -61,7 +59,7 @@ export default function AdminAppInformation_UiMain({
|
||||
</Group>
|
||||
|
||||
{selectPage === "1" && (
|
||||
<AdminAppInformation_ViewInformasiWhatApps nomorAdmin={nomorAdmin} />
|
||||
<AdminAppInformation_ViewInformasiWhatApps />
|
||||
)}
|
||||
|
||||
{selectPage === "2" && (
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
" use client";
|
||||
|
||||
import {
|
||||
AccentColor,
|
||||
AdminColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import { apiGetAdminContact } from "@/app_modules/_global/lib/api_fetch_master";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
ActionIcon,
|
||||
Button,
|
||||
Collapse,
|
||||
Grid,
|
||||
Group,
|
||||
Paper,
|
||||
Stack,
|
||||
@@ -11,41 +19,57 @@ import {
|
||||
Title,
|
||||
Tooltip,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import { IconEdit, IconPhone } from "@tabler/icons-react";
|
||||
import { useState } from "react";
|
||||
import { ComponentAdminGlobal_NotifikasiBerhasil } from "../../_admin_global/admin_notifikasi/notifikasi_berhasil";
|
||||
import { ComponentAdminGlobal_NotifikasiGagal } from "../../_admin_global/admin_notifikasi/notifikasi_gagal";
|
||||
import adminAppInformation_getNomorAdmin from "../fun/master/get_nomor_admin";
|
||||
import adminAppInformation_funUpdateNomorAdmin from "../fun/update/fun_update_nomor";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { AccentColor, AdminColor, MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
|
||||
export default function AdminAppInformation_ViewInformasiWhatApps({
|
||||
nomorAdmin,
|
||||
}: {
|
||||
nomorAdmin: any;
|
||||
}) {
|
||||
const [dataNomor, setDataNomor] = useState(nomorAdmin);
|
||||
export default function AdminAppInformation_ViewInformasiWhatApps() {
|
||||
const [dataNomor, setDataNomor] = useState<any | null>(null);
|
||||
const [updateNomor, setUpdateNomor] = useState("");
|
||||
const [opened, { toggle }] = useDisclosure(false);
|
||||
|
||||
async function onUpdate() {
|
||||
const newNumber = (dataNomor.nomor = updateNomor);
|
||||
setDataNomor({
|
||||
...dataNomor,
|
||||
nomor: newNumber,
|
||||
});
|
||||
useShallowEffect(() => {
|
||||
handleLoadData();
|
||||
}, []);
|
||||
|
||||
const updt = await adminAppInformation_funUpdateNomorAdmin({
|
||||
data: dataNomor,
|
||||
});
|
||||
if (updt.status === 200) {
|
||||
const loadDdata = await adminAppInformation_getNomorAdmin();
|
||||
setDataNomor(loadDdata);
|
||||
toggle();
|
||||
ComponentAdminGlobal_NotifikasiBerhasil(updt.message);
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiGagal(updt.message);
|
||||
const handleLoadData = async () => {
|
||||
try {
|
||||
const response = await apiGetAdminContact();
|
||||
|
||||
if (response) {
|
||||
setDataNomor(response.data);
|
||||
} else {
|
||||
setDataNomor("");
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get admin contact", error);
|
||||
setDataNomor("");
|
||||
}
|
||||
};
|
||||
|
||||
async function onUpdate() {
|
||||
try {
|
||||
const newNumber = (dataNomor.nomor = updateNomor);
|
||||
setDataNomor({
|
||||
...dataNomor,
|
||||
nomor: newNumber,
|
||||
});
|
||||
|
||||
const updt = await adminAppInformation_funUpdateNomorAdmin({
|
||||
data: dataNomor,
|
||||
});
|
||||
if (updt.status === 200) {
|
||||
handleLoadData();
|
||||
toggle();
|
||||
ComponentAdminGlobal_NotifikasiBerhasil(updt.message);
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiGagal(updt.message);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error update nomor admin", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,78 +83,96 @@ export default function AdminAppInformation_ViewInformasiWhatApps({
|
||||
p={"xs"}
|
||||
style={{ borderRadius: "6px" }}
|
||||
>
|
||||
<Title c={AdminColor.white} order={4}>Informasi WhatsApp</Title>
|
||||
<Title c={AdminColor.white} order={4}>
|
||||
Informasi WhatsApp
|
||||
</Title>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
<Paper w={"50%"} bg={AdminColor.softBlue} p={"md"}>
|
||||
<Stack>
|
||||
<Paper c={AdminColor.white} bg={AccentColor.darkblue} p={"xl"}>
|
||||
<Group position="apart">
|
||||
<Title order={2}>{`+${dataNomor.nomor}`}</Title>
|
||||
<Tooltip label={"Edit"}>
|
||||
<ActionIcon
|
||||
style={{ transition: "0.2s" }}
|
||||
variant="transparent"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
toggle();
|
||||
setUpdateNomor(dataNomor.nomor);
|
||||
}}
|
||||
<Grid>
|
||||
<Grid.Col span={4}>
|
||||
{!dataNomor ? (
|
||||
<CustomSkeleton height={100} width={300} />
|
||||
) : (
|
||||
<Paper bg={AdminColor.softBlue} p={"md"}>
|
||||
<Stack>
|
||||
<Paper
|
||||
c={AdminColor.white}
|
||||
bg={AccentColor.darkblue}
|
||||
p={"xl"}
|
||||
>
|
||||
<IconEdit
|
||||
style={{
|
||||
transition: "0.2s",
|
||||
}}
|
||||
color={AdminColor.white}
|
||||
/>
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
</Paper>
|
||||
<Group position="apart">
|
||||
<Title order={2}>{`+${dataNomor?.nomor}`}</Title>
|
||||
<Tooltip label={"Edit"}>
|
||||
<ActionIcon
|
||||
style={{ transition: "0.2s" }}
|
||||
variant="transparent"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
toggle();
|
||||
setUpdateNomor(dataNomor?.nomor);
|
||||
}}
|
||||
>
|
||||
<IconEdit
|
||||
style={{
|
||||
transition: "0.2s",
|
||||
}}
|
||||
color={opened ? "gray" : AdminColor.white}
|
||||
/>
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
</Paper>
|
||||
|
||||
<Collapse
|
||||
in={opened}
|
||||
transitionDuration={300}
|
||||
transitionTimingFunction="linear"
|
||||
>
|
||||
<Stack>
|
||||
<TextInput
|
||||
type="number"
|
||||
placeholder="Update nomor admin"
|
||||
icon={<IconPhone />}
|
||||
value={updateNomor}
|
||||
label={<Title order={6}>Nomor Aktif Admin</Title>}
|
||||
onChange={(val) => {
|
||||
setUpdateNomor(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
<Group position="right">
|
||||
<Button
|
||||
style={{ transition: "0.2s" }}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
toggle();
|
||||
}}
|
||||
<Collapse
|
||||
in={opened}
|
||||
transitionDuration={300}
|
||||
transitionTimingFunction="linear"
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
style={{ transition: "0.2s" }}
|
||||
disabled={updateNomor === "" ? true : false}
|
||||
color="green"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onUpdate();
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Collapse>
|
||||
</Stack>
|
||||
</Paper>
|
||||
<Stack>
|
||||
<TextInput
|
||||
type="number"
|
||||
placeholder="Update nomor admin"
|
||||
icon={<IconPhone />}
|
||||
value={updateNomor}
|
||||
label={
|
||||
<Title c="white" order={6}>
|
||||
Nomor Aktif Admin
|
||||
</Title>
|
||||
}
|
||||
onChange={(val) => {
|
||||
setUpdateNomor(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
<Group position="right">
|
||||
<Button
|
||||
style={{ transition: "0.2s" }}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
toggle();
|
||||
}}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
style={{ transition: "0.2s" }}
|
||||
disabled={updateNomor === "" ? true : false}
|
||||
color="green"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onUpdate();
|
||||
}}
|
||||
>
|
||||
Update
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Collapse>
|
||||
</Stack>
|
||||
</Paper>
|
||||
)}
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -37,7 +37,7 @@ const apiPostVerifikasiCodeOtp = async ({ nomor }: { nomor: string }) => {
|
||||
};
|
||||
|
||||
const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: string }) => {
|
||||
const respone = await fetch(`/api/auth/code/${id}/peserta`, {
|
||||
const respone = await fetch(`/api/auth/code/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
Reference in New Issue
Block a user