Refactor Omada actions and enhance payment processing

- Simplified fetchOmadaGroupProfiles function by removing unnecessary parameters and using environment variables for base URL and API key.
- Improved error handling in fetchOmadaGroupProfiles to check for error codes in the response.
- Updated addDevicesToGroup function to remove redundant parameters and streamline device addition logic.
- Integrated formatMacAddress utility to ensure consistent MAC address formatting during payment verification.
- Enhanced verifyPayment function to include device addition upon successful payment verification, with improved logging.
- Refactored DevicesToPay component to clean up payment verification logic and improve UI responsiveness.

These changes enhance the clarity and efficiency of device management and payment processing functionalities.
This commit is contained in:
2024-12-21 00:24:29 +05:00
parent 1d6f4faf7e
commit 586c0e7210
4 changed files with 57 additions and 86 deletions

View File

@ -77,7 +77,7 @@ export default function DevicesToPay({
disabled={verifying}
onClick={async () => {
setVerifying(true);
const res = await verifyPayment({
await verifyPayment({
paymentId: payment?.id,
benefName: user?.name ?? "",
accountNo: user?.accNo ?? "",
@ -85,16 +85,16 @@ export default function DevicesToPay({
time: formatDate(new Date(payment?.createdAt || "")),
});
setVerifying(false);
switch (true) {
case res.success === true:
toast.success(res.message);
break;
case res.success === false:
toast.error(res.message);
break;
default:
toast.error("Unexpected error occurred.");
}
// switch (true) {
// case res?.success === true:
// toast.success(res.message);
// break;
// case res.success === false:
// toast.error(res.message);
// break;
// default:
// toast.error("Unexpected error occurred.");
// }
}}
size={"lg"} className="mb-4">
{verifying ? "Verifying..." : "Verify Payment"}
@ -104,16 +104,16 @@ export default function DevicesToPay({
</div>
</TableCaption>
<TableBody>
<TableBody className="">
<TableRow>
<TableCell>Total Devices</TableCell>
<TableCell className="text-right">{devices?.length}</TableCell>
<TableCell className="text-right text-xl">{devices?.length}</TableCell>
</TableRow>
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={1}>Total</TableCell>
<TableCell className="text-right">{total.toFixed(2)}</TableCell>
<TableRow className="">
<TableCell colSpan={1}>Total Due</TableCell>
<TableCell className="text-right text-3xl font-bold">{total.toFixed(2)}</TableCell>
</TableRow>
</TableFooter>
</Table>