update inprime date on agent balance sub module

This commit is contained in:
bagus2112
2025-11-20 11:43:41 +07:00
parent 90d06a8b66
commit e128f2681b

View File

@ -50,19 +50,15 @@ const AgentBalance = () => {
const [dialogOpen, setDialogOpen] = useState(false); const [dialogOpen, setDialogOpen] = useState(false);
const [isReloading, setIsReloading] = useState(false); const [isReloading, setIsReloading] = useState(false);
const [barcode, setBarcode] = useState(''); const [barcode, setBarcode] = useState('');
const [requested_date, setRequested_date] = useState('');
const [token_legacy, setToken_legacy] = useState(''); const [token_legacy, setToken_legacy] = useState('');
// const [selectedMember, setSelectedMember] = useState(initBalance); // const [selectedMember, setSelectedMember] = useState(initBalance);
useEffect(() => { useEffect(() => {
// fetchAgentBalance(); // fetchAgentBalance();
}, []); }, []);
const fetchAgentBalance = async ( const fetchAgentBalance = async (page: number, limit: number, sorting: any, filter: any) => {
page: number,
limit: number,
sorting: any,
filter: any
) => {
filter = filter.length ? filter : {}; filter = filter.length ? filter : {};
let balances = await axios.get(`${BASE_URL}/customer/agent-balance`, { let balances = await axios.get(`${BASE_URL}/customer/agent-balance`, {
params: { params: {
@ -78,11 +74,11 @@ const AgentBalance = () => {
let temp = 1; let temp = 1;
let resBalance = balances.data.data.list.map((el: any) => { let resBalance = balances.data.data.list.map((el: any) => {
el.no = temp++; el.no = temp++;
if (!el.agent_name) el.agent_name = '' if (!el.agent_name) el.agent_name = '';
return el; return el;
}); });
return { data: resBalance, totalCount: balances?.data.data.total_count } return { data: resBalance, totalCount: balances?.data.data.total_count };
} };
const openDialog = () => setIsDialogOpen(true); const openDialog = () => setIsDialogOpen(true);
const closeDialog = () => { const closeDialog = () => {
@ -100,24 +96,35 @@ const AgentBalance = () => {
setFormData(data); setFormData(data);
setDialogType('update'); setDialogType('update');
setIsDialogOpen(true); setIsDialogOpen(true);
let getTokenLegacy = await axios.get(`${BASE_URL}/token/get-token-legacy`, { params: { id: data.id } }); let getTokenLegacy = await axios.get(`${BASE_URL}/token/get-token-legacy`, {
params: { id: data.id }
});
let temp = getTokenLegacy?.data?.data?.token_legacy || ''; let temp = getTokenLegacy?.data?.data?.token_legacy || '';
setToken_legacy(temp) setToken_legacy(temp);
}; };
const handleReload = async () => { const handleReload = async () => {
setIsReloading(true); setIsReloading(true);
await fetchAgentBalance(currentPage, pageSize, '',''); await fetchAgentBalance(currentPage, pageSize, '', '');
closeDialog() closeDialog();
setIsReloading(false); setIsReloading(false);
// fetchAgentBalance(); // fetchAgentBalance();
}; };
function formatDate(value: string) {
const d = new Date(value);
const day = String(d.getDate()).padStart(2, '0');
const month = String(d.getMonth() + 1).padStart(2, '0');
const year = d.getFullYear();
return `${day}-${month}-${year}`;
}
async function getQrCode(customerId: any): Promise<void> { async function getQrCode(customerId: any): Promise<void> {
try { try {
setBarcode(``); setBarcode(``);
let getToken = await axios.get(`${BASE_URL}/token/get`, { params: { id: customerId } }); let getToken = await axios.get(`${BASE_URL}/token/get`, { params: { id: customerId } });
setBarcode(getToken.data.data.qrCode); setBarcode(getToken.data.data.qrCode);
setRequested_date(formatDate(getToken.data.data.requested_date));
} catch (error: any) { } catch (error: any) {
toast.warning(error.message); toast.warning(error.message);
console.log(error); console.log(error);
@ -156,10 +163,9 @@ const AgentBalance = () => {
</Breadcrumbs> </Breadcrumbs>
<div className="grid gap-5 lg:gap-7.5 mt-5 relative"> <div className="grid gap-5 lg:gap-7.5 mt-5 relative">
{isReloading && ( {isReloading && <DataGridLoader />}
<DataGridLoader /> {!isReloading && (
)} <DataGridProvider
{!isReloading && (<DataGridProvider
// data={dataBalance} // data={dataBalance}
pagination={{ size: pageSize }} pagination={{ size: pageSize }}
columns={getColumns(handleUpdate)} columns={getColumns(handleUpdate)}
@ -194,6 +200,7 @@ const AgentBalance = () => {
customerId={formData.id} customerId={formData.id}
agent_name={formData.agent_name} agent_name={formData.agent_name}
handleReload={handleReload} handleReload={handleReload}
date={requested_date}
/> />
</div> </div>
</DialogContent> </DialogContent>
@ -204,7 +211,15 @@ const AgentBalance = () => {
}; };
// ==================== // ====================
const PaymentCard = ({ barcode, agent_name, customerId, token_legacy, setToken_legacy, handleReload }: any) => { const PaymentCard = ({
barcode,
agent_name,
customerId,
token_legacy,
setToken_legacy,
handleReload,
date
}: any) => {
const cardRef: any = useRef(null); const cardRef: any = useRef(null);
const waitForImageLoad = (img: HTMLImageElement): Promise<void> => { const waitForImageLoad = (img: HTMLImageElement): Promise<void> => {
@ -216,7 +231,7 @@ const PaymentCard = ({ barcode, agent_name, customerId, token_legacy, setToken_l
img.onload = () => resolve(); img.onload = () => resolve();
} }
}); });
}; };
const handleDownload = async () => { const handleDownload = async () => {
if (!cardRef.current) return; if (!cardRef.current) return;
@ -252,7 +267,7 @@ const PaymentCard = ({ barcode, agent_name, customerId, token_legacy, setToken_l
toast.success(`Success Update Token Legacy`); toast.success(`Success Update Token Legacy`);
await handleReload(); await handleReload();
} catch (error: any) { } catch (error: any) {
let err_msg = error?.response?.data?.error || error.message let err_msg = error?.response?.data?.error || error.message;
toast.error(err_msg); toast.error(err_msg);
} }
}; };
@ -283,7 +298,7 @@ const PaymentCard = ({ barcode, agent_name, customerId, token_legacy, setToken_l
<div className="absolute bottom-16"> <div className="absolute bottom-16">
<div className="text-[13px] text-[#47173a] text-left font-medium leading-tight"> <div className="text-[13px] text-[#47173a] text-left font-medium leading-tight">
<p>Imprime husi : Telin Digital Solution</p> <p>Imprime husi : Telin Digital Solution</p>
<p>Imprime : 01062025</p> <p>Imprime : {date}</p>
</div> </div>
</div> </div>
</div> </div>