fix admin
deskripsi: - fix api nomor admin
This commit is contained in:
@@ -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>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user