fix member

This commit is contained in:
unknown
2025-04-08 21:58:32 +07:00
parent 3fe0eb8ffc
commit 3043b39c8c
3 changed files with 123 additions and 27 deletions

View File

@ -67,7 +67,7 @@ const Kyc = () => {
}); });
setMembers(resMembers); setMembers(resMembers);
} catch (error: any) { } catch (error: any) {
alert(error.message); toast.error(error.message);
console.log(error); console.log(error);
} }
} }
@ -117,6 +117,7 @@ const Kyc = () => {
delete updateData.group_updated_at; delete updateData.group_updated_at;
delete updateData.group_deleted_by; delete updateData.group_deleted_by;
delete updateData.group_deleted_at; delete updateData.group_deleted_at;
delete updateData.updated_at;
try { try {
if (dialogType === 'reject') { if (dialogType === 'reject') {
await axios.post(`${BASE_URL}/customer/reject`, { customerid: customerId }); await axios.post(`${BASE_URL}/customer/reject`, { customerid: customerId });
@ -134,7 +135,6 @@ const Kyc = () => {
setIsDialogOpen(false); setIsDialogOpen(false);
toast.success('Success Update Kyc Member'); toast.success('Success Update Kyc Member');
} catch (error: any) { } catch (error: any) {
alert(error.message);
setDialogOpen(false); setDialogOpen(false);
setIsDialogOpen(false); setIsDialogOpen(false);
toast.error(error.message); toast.error(error.message);
@ -156,15 +156,16 @@ const Kyc = () => {
onYes={handleYes} onYes={handleYes}
onNo={() => setDialogOpen(false)} onNo={() => setDialogOpen(false)}
/> />
<CustomerDialog { member.id ? (
open={isDialogOpen} <CustomerDialog
handleClose={closeDialog} open={isDialogOpen}
handleReject={handleReject} handleClose={closeDialog}
handleSubmit={handleSubmit} handleSubmit={handleSubmit}
initialData={member} initialData={member}
viewStats={true} viewStats={true}
page={'kyc'} page={'kyc'}
/> />
): ""}
<h1 className="text-xl font-medium leading-none text-gray-900 mb-3 grid gap-5 lg:gap-7.5 mx-8 w-auto">Manage Member KYC</h1> <h1 className="text-xl font-medium leading-none text-gray-900 mb-3 grid gap-5 lg:gap-7.5 mx-8 w-auto">Manage Member KYC</h1>
<div className='grid gap-5 lg:gap-7.5 mx-8 w-auto'> <div className='grid gap-5 lg:gap-7.5 mx-8 w-auto'>
<Breadcrumbs> <Breadcrumbs>

View File

@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import axios from 'axios'; import axios from 'axios';
import { Dialog,DialogActions,DialogContent,DialogTitle,TextField,Button,MenuItem,Select,InputLabel,FormControl,Typography, import { Dialog,DialogActions,DialogContent,DialogTitle,TextField,Button,MenuItem,Select,InputLabel,FormControl,Typography,
InputAdornment,Grid,Box InputAdornment,Grid,Box,List,ListItem,
} from "@mui/material"; } from "@mui/material";
import UploadFileIcon from "@mui/icons-material/UploadFile"; import UploadFileIcon from "@mui/icons-material/UploadFile";
import Divider from '@mui/material/Divider'; import Divider from '@mui/material/Divider';
@ -11,7 +11,7 @@ import ConfirmDialog from '@/components/confirm';
import { toast } from 'sonner'; import { toast } from 'sonner';
const BASE_URL_MASTER_DATA = apiConfig.service_master_data; const BASE_URL_MASTER_DATA = apiConfig.service_master_data;
const BASE_URL_CUSTOMER = apiConfig.service_customer; const BASE_URL_CUSTOMER = apiConfig.service_customer;
// MAIN PAGE
const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStats, handleReject, page, fetchCustomers }: any) => { const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStats, handleReject, page, fetchCustomers }: any) => {
const [formData, setFormData] = useState(initialData || initialMember); const [formData, setFormData] = useState(initialData || initialMember);
const [viewOnly, setViewOnly] = useState(viewStats || false); const [viewOnly, setViewOnly] = useState(viewStats || false);
@ -80,7 +80,8 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat
const handleChange = async (e: any) => { const handleChange = async (e: any) => {
const { name, value } = e.target; const { name, value } = e.target;
if (name === 'municipio' || name === 'posto_adms' || name === 'suco') await getMasterAfter(name, value); if (name === 'municipio' || name === 'posto_adms' || name === 'suco') await getMasterAfter(name, value);
if (name === "file_selfie" || name === "photouser") { // FOR FILE ONLY if (name === "file_selfie" || name === "photouser" || name === 'file_document_id' || name === "file_document_id_selfie" ||
name === "file_commercial_license") { // FOR FILE ONLY
setFormData({ ...formData, [name]: e.target.files[0] }); setFormData({ ...formData, [name]: e.target.files[0] });
} else { } else {
setFormData({ ...formData, [name]: value }); setFormData({ ...formData, [name]: value });
@ -127,8 +128,9 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat
} }
const onSubmit = () => { const onSubmit = () => {
if (page === 'kyc' && !formData.description) return toast.warning(`Description for approval needed!`)
handleSubmit(formData); handleSubmit(formData);
handleClose(); // handleClose();
}; };
const onReject = () => { const onReject = () => {
@ -274,9 +276,13 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat
page === 'kyc' ? ( page === 'kyc' ? (
<> <>
<Typography sx={{color:'grey'}}>Approval</Typography> <Typography sx={{color:'grey'}}>Approval</Typography>
<TextField fullWidth margin="dense" label="Approval Description" name="description" value={formData.description} onChange={handleChange} /> <TextField fullWidth required={page === 'kyc'?true:false} margin="dense" label="Approval Description" name="description" value={formData.description} onChange={handleChange} />
</> </>
) : (<>{getAdmAccess(page, formData, handleClose, fetchCustomers, viewOnly, setViewOnly)}</>) ) : (<>
{getAdmAccess(page, formData, handleClose, fetchCustomers, viewOnly, setViewOnly)}
<Divider className="pt-7"/>
{formData.id ? showCustomerWallet(formData.id) : ""}
</>)
} }
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
@ -317,11 +323,11 @@ function fileTextFile(label: string, value: any, name: string, handleChange: any
<input <input
type="file" type="file"
id="file-upload" id="file-upload"
style={{ display: "none" }} // style={{ display: "none" }}
onChange={handleChange} onChange={handleChange}
name={name} name={name}
/> />
<label htmlFor="file-upload"> {/* <label htmlFor="file-upload">
<Button <Button
component="span" component="span"
variant="contained" variant="contained"
@ -330,14 +336,14 @@ function fileTextFile(label: string, value: any, name: string, handleChange: any
> >
Browse Browse
</Button> </Button>
</label> </label> */}
</InputAdornment> </InputAdornment>
), ),
}} }}
/> />
) )
} }
// ACCESS ADM
function getAdmAccess(page: string, data: any, handleClose: any, fetchCustomers: any, viewOnly: any, setViewOnly: any) { function getAdmAccess(page: string, data: any, handleClose: any, fetchCustomers: any, viewOnly: any, setViewOnly: any) {
const [dialogOpen, setDialogOpen] = useState(false); const [dialogOpen, setDialogOpen] = useState(false);
const [dialogType, setDialogType] = useState(''); const [dialogType, setDialogType] = useState('');
@ -517,7 +523,83 @@ function getPinStatus(status: string) {
res: null res: null
} }
} }
// CUSTOMER WALLET
function showCustomerWallet(customerid: any) {
const [dialogOpen, setDialogOpen] = useState(false);
const [customerWallet, setCustomerWallet] = useState([]);
if (!customerid) return ''
function showCustomerWallet() { useEffect(() => {
fetchCustomerWallet()
}, []);
async function fetchCustomerWallet() {
try {
let getCustWallet = await axios.get(`${BASE_URL_CUSTOMER}/customer/wallet`, { params: { customerid: customerid }});
setCustomerWallet(getCustWallet.data.data.wallets)
} catch (error: any) {
toast.error(error.message)
}
}
const handleYes = async () => {}
return (
<Box p={3} boxShadow={3} borderRadius={2} bgcolor="white">
<Typography variant="h6" gutterBottom>Wallet Member</Typography>
<Grid>
<List>
{customerWallet.map((item:any, index:any) => (
<React.Fragment key={item.id}>
<ListItem
sx={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
px: 2,
py: 1.5,
bgcolor: index % 2 === 0 ? 'grey.50' : 'background.paper',
borderRadius: 2,
'&:hover': {
bgcolor: 'grey.100',
},
}}
>
<Box>
<Typography variant="subtitle2" color="text.secondary">
Name
</Typography>
<Typography variant="body1" fontWeight={500}>
{item.wallet.name}
</Typography>
</Box>
<Box>
<Typography variant="subtitle2" color="text.secondary">
Description
</Typography>
<Typography variant="body1">{item.wallet.description}</Typography>
</Box>
<Box>
<Typography variant="subtitle2" color="text.secondary">
Transaction Today
</Typography>
<Typography variant="body1">{item.transaction_number_today}</Typography>
</Box>
</ListItem>
{index < customerWallet.length - 1 && <Divider sx={{ my: 1 }} />}
</React.Fragment>
))}
</List>
</Grid>
<ConfirmDialog
open={dialogOpen}
onClose={() => setDialogOpen(false)}
title="Confirm Action"
content={`Are you sure you want to show?`}
onYes={handleYes}
onNo={() => setDialogOpen(false)}
/>
</Box>
)
} }

View File

@ -20,7 +20,10 @@ const ManageMembers = () => {
const [isDialogOpen, setIsDialogOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false); const [dialogOpen, setDialogOpen] = useState(false);
const [dialogType, setDialogType] = useState(''); const [dialogType, setDialogType] = useState('');
const closeDialog = () => setIsDialogOpen(false); const closeDialog = () => {
setIsDialogOpen(false)
setMember(initialMember)
};
const { getUser } = useAuthContext(); const { getUser } = useAuthContext();
useEffect(() => { useEffect(() => {
@ -48,7 +51,7 @@ const ManageMembers = () => {
}); });
setMembers(resMembers); setMembers(resMembers);
} catch (error: any) { } catch (error: any) {
alert(error.message); toast.error(error.message);
console.log(error); console.log(error);
} }
} }
@ -99,8 +102,16 @@ const ManageMembers = () => {
delete updateData.group_deleted_at; delete updateData.group_deleted_at;
delete updateData.updated_at; delete updateData.updated_at;
try { try {
if (dialogType === 'update') const form = new FormData();
await axios.put(`${BASE_URL}/customer/update/${selectedMember}`, updateData); for (const property in updateData) {
if (updateData[property]) form.append(property, updateData[property]);
}
if (dialogType === 'update') await axios.put(`${BASE_URL}/customer/update/${selectedMember}`, form, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
// if (dialogType === 'create') await axios.post(`${BASE_URL}/customers/create`, member) // if (dialogType === 'create') await axios.post(`${BASE_URL}/customers/create`, member)
await fetchCustomers(); await fetchCustomers();
setDialogOpen(false); setDialogOpen(false);
@ -130,12 +141,14 @@ const ManageMembers = () => {
onYes={handleYes} onYes={handleYes}
onNo={() => setDialogOpen(false)} onNo={() => setDialogOpen(false)}
/> />
<CustomerDialog { member.id ? (
<CustomerDialog
open={isDialogOpen} open={isDialogOpen}
handleClose={closeDialog} handleClose={closeDialog}
handleSubmit={handleSubmit} handleSubmit={handleSubmit}
initialData={member} initialData={member}
/> />
): ""}
<h1 className="text-xl font-medium leading-none text-gray-900 mb-3 grid gap-5 lg:gap-7.5 mx-8 w-auto">Manage Members</h1> <h1 className="text-xl font-medium leading-none text-gray-900 mb-3 grid gap-5 lg:gap-7.5 mx-8 w-auto">Manage Members</h1>
<div className='grid gap-5 lg:gap-7.5 mx-8 w-auto'> <div className='grid gap-5 lg:gap-7.5 mx-8 w-auto'>
<Breadcrumbs> <Breadcrumbs>