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