import { useState, useEffect } from 'react'; import axios from 'axios'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; import { apiConfig } from '@/config/api.config'; import ConfirmDialog from '@/components/confirm'; const BASE_URL_CUSTOMER = apiConfig.service_customer; // ACCESS ADM export default function AdmAccess( page: string, data: any, handleClose: any, fetchCustomers: any, viewOnly: any, setViewOnly: any ) { const [dialogOpen, setDialogOpen] = useState(false); const [dialogType, setDialogType] = useState(''); const [changeGroup, setChangeGroup] = useState(''); const [changeGroupD, setChangeGroupD] = useState(false); const [groups, setGroups] = useState([]); useEffect(() => { fetchGroups(); }, []); const fetchGroups = async () => { try { let getGroups = await axios.get(`${BASE_URL_CUSTOMER}/groups/list`, { params: { limit: 50, page: 1, with_deleted: false, order_field: 'name', order_direction: 'ASC' } }); setGroups(getGroups.data.data.list); } catch (error: any) { toast.error(error.message); } }; const handleYes = async () => { try { if (dialogType === 'update status') { let statusNext = getPinStatus(data.status).res; if (statusNext) await axios.put(`${BASE_URL_CUSTOMER}/customer/statuspin`, { customerid: data.id, status: statusNext }); else toast.error('Handle Active/Suspend only'); await fetchCustomers(); toast.success('Success Update Status'); } if (dialogType === 'reset pin') { if (data.id) await axios.post(`${BASE_URL_CUSTOMER}/customer/resetpin`, { customerid: data.id }); else throw { message: 'data.id not found' }; await fetchCustomers(); toast.success('Pin will send to customer MSISDN'); } } catch (error: any) { toast.error(error.message); } finally { setDialogOpen(false); handleClose(); } }; function buttonStatus(e: any) { e.preventDefault(); setDialogType('update status'); setDialogOpen(true); } function buttonResetPin(e: any) { e.preventDefault(); setDialogType('reset pin'); setDialogOpen(true); } async function buttonChangeGroup() { try { let dataObj = { customerid: data.id, destination_group: changeGroup }; if (data.group_id === changeGroup) throw { message: `You update same group as the exist customer group` }; if (dataObj.customerid && dataObj.destination_group) { await axios.post(`${BASE_URL_CUSTOMER}/customer/change-group`, dataObj); } toast.success('Success Change group'); await fetchCustomers(); setChangeGroupD(false); handleClose(); } catch (error: any) { console.log(error); toast.error(error.message); } } function openChangeGroupDialog(e: any) { e.preventDefault(); setChangeGroup(data.group_id); setChangeGroupD(true); } function btnConfirmDialog(status: boolean) { setDialogOpen(status); } if (page !== 'kyc') { return (
Pin Status: {getPinStatus(data.status).msg}
Reset PIN
Change Group
Edit Member