@@ -213,11 +201,12 @@ const EditDialog = () => {
+ {errors.id_currency_origin && (
+ {errors.id_currency_origin}
+ )}
+ {errors.id_currency_destination && (
+
+ {errors.id_currency_destination}
+
+ )}
diff --git a/src/pages/master/conversion/blocks/Types.ts b/src/pages/master/conversion/blocks/Types.ts
new file mode 100644
index 0000000..196e0a0
--- /dev/null
+++ b/src/pages/master/conversion/blocks/Types.ts
@@ -0,0 +1,47 @@
+import { toast } from 'sonner';
+
+export const validateForm = (formField: any, setErrors: any) => {
+ const requiredFields = [
+ { key: 'id_currency_origin', label: 'Currency Origin' },
+ { key: 'id_currency_destination', label: 'Currency Destination' },
+ { key: 'buy', label: 'Buy' },
+ { key: 'sell', label: 'Sell' },
+ { key: 'status', label: 'Status' }
+ ];
+
+ const newErrors: Record = {};
+ let isValid = true;
+
+ requiredFields.forEach(({ key, label }) => {
+ if (
+ formField[key as keyof typeof formField] === '' ||
+ formField[key as keyof typeof formField] === null ||
+ formField[key as keyof typeof formField] === undefined
+ ) {
+ newErrors[key] = `${label} is required`;
+ toast.error(`${label} is required`);
+ isValid = false;
+ }
+ });
+
+ setErrors(newErrors);
+ return isValid;
+};
+
+export const initialState: {
+ status: string;
+ id_currency_origin: string;
+ id_currency_destination: string;
+ buy: number | null;
+ sell: number | null;
+ created_by: string;
+ created_at: string;
+} = {
+ status: '',
+ id_currency_origin: '',
+ id_currency_destination: '',
+ buy: null,
+ sell: null,
+ created_by: '',
+ created_at: ''
+};