feat : update member

Deskripsi:
- update api member
- update type member
- update list member
- update create member
- update edit member
- update active and non active

No Issue
This commit is contained in:
lukman
2024-08-12 11:59:44 +08:00
parent 655df62dc6
commit 43c4690a28
23 changed files with 619 additions and 592 deletions

View File

@@ -1,4 +1,4 @@
'use client'
"use client";
import { API_ADDRESS, WARNA } from "@/module/_global";
import LayoutModal from "@/module/_global/layout/layout_modal";
import { Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core";
@@ -8,76 +8,93 @@ import { useState } from "react";
import toast from "react-hot-toast";
import { FaPencil, FaToggleOff } from "react-icons/fa6";
import { ImUserCheck } from "react-icons/im";
import { funEditStatusMember } from "../lib/api_member";
export default function DrawerDetailMember({ onDeleted, id, status }: { onDeleted: (val: boolean) => void, id: string | undefined, status: boolean |undefined }) {
const router = useRouter()
const [isModal, setModal] = useState(false)
export default function DrawerDetailMember({
onDeleted,
id,
status,
}: {
onDeleted: (val: boolean) => void;
id: string;
status: boolean;
}) {
const router = useRouter();
const [isModal, setModal] = useState(false);
async function nonActive(val: boolean) {
try {
const res = await funEditStatusMember(id, {
isActive: status,
});
async function nonActive(val: boolean) {
try {
const res = await fetch(API_ADDRESS.apiDeleteUser, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id,
isActive: status
}),
})
if (res.status == 200) {
onDeleted(true);
} else {
onDeleted(false);
}
router.push('/member')
setModal(false)
} catch (error) {
console.error(error)
setModal(false);
toast.error("Terjadi kesalahan");
if (res.success) {
toast.success(res.message);
onDeleted(true);
} else {
onDeleted(false);
}
}
router.push("/member?active=true");
setModal(false);
} catch (error) {
console.error(error);
setModal(false);
toast.error("Terjadi kesalahan");
}
}
return (
<Box>
<Stack pt={10}>
<SimpleGrid
cols={{ base: 3, sm: 3, lg: 3 }}
>
<Flex justify={'center'} align={'center'} direction={'column'}
style={{ cursor: 'pointer' }}
onClick={() => {
setModal(true)
}}
>
<Box>
<FaToggleOff size={30} color={WARNA.biruTua} />
</Box>
<Box>
<Text c={WARNA.biruTua} ta='center'> {status === false ? "Aktifkan" : "Non Aktifkan"}</Text>
</Box>
</Flex>
return (
<Box>
<Stack pt={10}>
<SimpleGrid cols={{ base: 3, sm: 3, lg: 3 }}>
<Flex
justify={"center"}
align={"center"}
direction={"column"}
style={{ cursor: "pointer" }}
onClick={() => {
setModal(true);
}}
>
<Box>
<FaToggleOff size={30} color={WARNA.biruTua} />
</Box>
<Box>
<Text c={WARNA.biruTua} ta="center">
{" "}
{status === false ? "Aktifkan" : "Non Aktifkan"}
</Text>
</Box>
</Flex>
<Flex justify={'center'} align={'center'} direction={'column'}
style={{ cursor: 'pointer' }}
onClick={() => {
router.push(`/member/edit/${id}`)
}}
>
<Box>
<FaPencil size={30} color={WARNA.biruTua} />
</Box>
<Box>
<Text c={WARNA.biruTua} ta='center'>Edit</Text>
</Box>
</Flex>
</SimpleGrid>
</Stack>
<LayoutModal opened={isModal} onClose={() => setModal(false)}
description="Apakah Anda yakin ingin mengubah status aktifasi anggota?"
onYes={(val) => { nonActive(val) }} />
</Box>
)
}
<Flex
justify={"center"}
align={"center"}
direction={"column"}
style={{ cursor: "pointer" }}
onClick={() => {
router.push(`/member/edit/${id}`);
}}
>
<Box>
<FaPencil size={30} color={WARNA.biruTua} />
</Box>
<Box>
<Text c={WARNA.biruTua} ta="center">
Edit
</Text>
</Box>
</Flex>
</SimpleGrid>
</Stack>
<LayoutModal
opened={isModal}
onClose={() => setModal(false)}
description="Apakah Anda yakin ingin mengubah status aktifasi anggota?"
onYes={(val) => {
nonActive(val);
}}
/>
</Box>
);
}