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";
|
import { AdminAppInformation_UiMain } from "@/app_modules/admin/app_info/ui";
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const nomorAdmin = await adminAppInformation_getNomorAdmin();
|
|
||||||
const listBank = await adminAppInformation_getMasterBank();
|
const listBank = await adminAppInformation_getMasterBank();
|
||||||
const dataBidangBisnis = await adminAppInformation_funGetBidangBisnis()
|
const dataBidangBisnis = await adminAppInformation_funGetBidangBisnis()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AdminAppInformation_UiMain
|
<AdminAppInformation_UiMain
|
||||||
nomorAdmin={nomorAdmin}
|
|
||||||
listBank={listBank}
|
listBank={listBank}
|
||||||
dataBidangBisnis={dataBidangBisnis}
|
dataBidangBisnis={dataBidangBisnis}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
export { apiGetMasterBank, apiGetMasterBidangBisnis, apiGetMasterStatusTransaksi };
|
export {
|
||||||
|
apiGetMasterBank,
|
||||||
|
apiGetMasterBidangBisnis,
|
||||||
|
apiGetMasterStatusTransaksi,
|
||||||
|
apiGetAdminContact,
|
||||||
|
};
|
||||||
|
|
||||||
const apiGetMasterBank = async () => {
|
const apiGetMasterBank = async () => {
|
||||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
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);
|
if (!token) return await token.json().catch(() => null);
|
||||||
|
|
||||||
const response = await fetch(`/api/master/status_transaksi`, {
|
const response = await fetch(`/api/master/status_transaksi`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
return await response.json().catch(() => null);
|
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;
|
data: any;
|
||||||
}) {
|
}) {
|
||||||
const updt = await prisma.nomorAdmin.update({
|
try {
|
||||||
where: {
|
const updt = await prisma.nomorAdmin.update({
|
||||||
id: data.id,
|
where: {
|
||||||
},
|
id: data.id,
|
||||||
data: {
|
},
|
||||||
nomor: data.nomor,
|
data: {
|
||||||
},
|
nomor: data.nomor,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!updt) return { status: 400, message: "Gagal update" };
|
if (!updt) return { status: 400, message: "Gagal update" };
|
||||||
return { status: 200, message: "Berhasil 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";
|
import { AccentColor, AdminColor, MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||||
|
|
||||||
export default function AdminAppInformation_UiMain({
|
export default function AdminAppInformation_UiMain({
|
||||||
nomorAdmin,
|
|
||||||
listBank,
|
listBank,
|
||||||
dataBidangBisnis,
|
dataBidangBisnis,
|
||||||
}: {
|
}: {
|
||||||
nomorAdmin: any;
|
|
||||||
listBank: any[];
|
listBank: any[];
|
||||||
dataBidangBisnis: any[];
|
dataBidangBisnis: any[];
|
||||||
}) {
|
}) {
|
||||||
@@ -61,7 +59,7 @@ export default function AdminAppInformation_UiMain({
|
|||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{selectPage === "1" && (
|
{selectPage === "1" && (
|
||||||
<AdminAppInformation_ViewInformasiWhatApps nomorAdmin={nomorAdmin} />
|
<AdminAppInformation_ViewInformasiWhatApps />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{selectPage === "2" && (
|
{selectPage === "2" && (
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
" use client";
|
" 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 {
|
import {
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
Button,
|
Button,
|
||||||
Collapse,
|
Collapse,
|
||||||
|
Grid,
|
||||||
Group,
|
Group,
|
||||||
Paper,
|
Paper,
|
||||||
Stack,
|
Stack,
|
||||||
@@ -11,41 +19,57 @@ import {
|
|||||||
Title,
|
Title,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
|
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||||
import { IconEdit, IconPhone } from "@tabler/icons-react";
|
import { IconEdit, IconPhone } from "@tabler/icons-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ComponentAdminGlobal_NotifikasiBerhasil } from "../../_admin_global/admin_notifikasi/notifikasi_berhasil";
|
import { ComponentAdminGlobal_NotifikasiBerhasil } from "../../_admin_global/admin_notifikasi/notifikasi_berhasil";
|
||||||
import { ComponentAdminGlobal_NotifikasiGagal } from "../../_admin_global/admin_notifikasi/notifikasi_gagal";
|
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 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({
|
export default function AdminAppInformation_ViewInformasiWhatApps() {
|
||||||
nomorAdmin,
|
const [dataNomor, setDataNomor] = useState<any | null>(null);
|
||||||
}: {
|
|
||||||
nomorAdmin: any;
|
|
||||||
}) {
|
|
||||||
const [dataNomor, setDataNomor] = useState(nomorAdmin);
|
|
||||||
const [updateNomor, setUpdateNomor] = useState("");
|
const [updateNomor, setUpdateNomor] = useState("");
|
||||||
const [opened, { toggle }] = useDisclosure(false);
|
const [opened, { toggle }] = useDisclosure(false);
|
||||||
|
|
||||||
async function onUpdate() {
|
useShallowEffect(() => {
|
||||||
const newNumber = (dataNomor.nomor = updateNomor);
|
handleLoadData();
|
||||||
setDataNomor({
|
}, []);
|
||||||
...dataNomor,
|
|
||||||
nomor: newNumber,
|
|
||||||
});
|
|
||||||
|
|
||||||
const updt = await adminAppInformation_funUpdateNomorAdmin({
|
const handleLoadData = async () => {
|
||||||
data: dataNomor,
|
try {
|
||||||
});
|
const response = await apiGetAdminContact();
|
||||||
if (updt.status === 200) {
|
|
||||||
const loadDdata = await adminAppInformation_getNomorAdmin();
|
if (response) {
|
||||||
setDataNomor(loadDdata);
|
setDataNomor(response.data);
|
||||||
toggle();
|
} else {
|
||||||
ComponentAdminGlobal_NotifikasiBerhasil(updt.message);
|
setDataNomor("");
|
||||||
} else {
|
}
|
||||||
ComponentAdminGlobal_NotifikasiGagal(updt.message);
|
} 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"}
|
p={"xs"}
|
||||||
style={{ borderRadius: "6px" }}
|
style={{ borderRadius: "6px" }}
|
||||||
>
|
>
|
||||||
<Title c={AdminColor.white} order={4}>Informasi WhatsApp</Title>
|
<Title c={AdminColor.white} order={4}>
|
||||||
|
Informasi WhatsApp
|
||||||
|
</Title>
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Paper w={"50%"} bg={AdminColor.softBlue} p={"md"}>
|
<Grid>
|
||||||
<Stack>
|
<Grid.Col span={4}>
|
||||||
<Paper c={AdminColor.white} bg={AccentColor.darkblue} p={"xl"}>
|
{!dataNomor ? (
|
||||||
<Group position="apart">
|
<CustomSkeleton height={100} width={300} />
|
||||||
<Title order={2}>{`+${dataNomor.nomor}`}</Title>
|
) : (
|
||||||
<Tooltip label={"Edit"}>
|
<Paper bg={AdminColor.softBlue} p={"md"}>
|
||||||
<ActionIcon
|
<Stack>
|
||||||
style={{ transition: "0.2s" }}
|
<Paper
|
||||||
variant="transparent"
|
c={AdminColor.white}
|
||||||
radius={"xl"}
|
bg={AccentColor.darkblue}
|
||||||
onClick={() => {
|
p={"xl"}
|
||||||
toggle();
|
|
||||||
setUpdateNomor(dataNomor.nomor);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<IconEdit
|
<Group position="apart">
|
||||||
style={{
|
<Title order={2}>{`+${dataNomor?.nomor}`}</Title>
|
||||||
transition: "0.2s",
|
<Tooltip label={"Edit"}>
|
||||||
}}
|
<ActionIcon
|
||||||
color={AdminColor.white}
|
style={{ transition: "0.2s" }}
|
||||||
/>
|
variant="transparent"
|
||||||
</ActionIcon>
|
radius={"xl"}
|
||||||
</Tooltip>
|
onClick={() => {
|
||||||
</Group>
|
toggle();
|
||||||
</Paper>
|
setUpdateNomor(dataNomor?.nomor);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconEdit
|
||||||
|
style={{
|
||||||
|
transition: "0.2s",
|
||||||
|
}}
|
||||||
|
color={opened ? "gray" : AdminColor.white}
|
||||||
|
/>
|
||||||
|
</ActionIcon>
|
||||||
|
</Tooltip>
|
||||||
|
</Group>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
<Collapse
|
<Collapse
|
||||||
in={opened}
|
in={opened}
|
||||||
transitionDuration={300}
|
transitionDuration={300}
|
||||||
transitionTimingFunction="linear"
|
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();
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Batal
|
<Stack>
|
||||||
</Button>
|
<TextInput
|
||||||
<Button
|
type="number"
|
||||||
style={{ transition: "0.2s" }}
|
placeholder="Update nomor admin"
|
||||||
disabled={updateNomor === "" ? true : false}
|
icon={<IconPhone />}
|
||||||
color="green"
|
value={updateNomor}
|
||||||
radius={"xl"}
|
label={
|
||||||
onClick={() => {
|
<Title c="white" order={6}>
|
||||||
onUpdate();
|
Nomor Aktif Admin
|
||||||
}}
|
</Title>
|
||||||
>
|
}
|
||||||
Update
|
onChange={(val) => {
|
||||||
</Button>
|
setUpdateNomor(val.currentTarget.value);
|
||||||
</Group>
|
}}
|
||||||
</Stack>
|
/>
|
||||||
</Collapse>
|
<Group position="right">
|
||||||
</Stack>
|
<Button
|
||||||
</Paper>
|
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>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const apiPostVerifikasiCodeOtp = async ({ nomor }: { nomor: string }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: 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",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
Reference in New Issue
Block a user