update type safe module conversion
This commit is contained in:
@ -35,7 +35,7 @@ import {
|
|||||||
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
import { initialState, validateForm } from './Types';
|
import { initialStateConversion, validateFormConversion } from './Types';
|
||||||
interface CurrencyProps {
|
interface CurrencyProps {
|
||||||
ID: string;
|
ID: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -52,13 +52,13 @@ const AddDialog = () => {
|
|||||||
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
const [formField, setFormField] = useState(initialState);
|
const [formField, setFormField] = useState(initialStateConversion);
|
||||||
const created_time = new Date();
|
const created_time = new Date();
|
||||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateConversion);
|
||||||
setErrors({});
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ const AddDialog = () => {
|
|||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!validateForm(formField, setErrors)) {
|
if (!validateFormConversion(formField, setErrors)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ import {
|
|||||||
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
import { initialState, validateForm } from './Types';
|
import { initialStateConversion, validateFormConversion } from './Types';
|
||||||
interface CurrencyProps {
|
interface CurrencyProps {
|
||||||
ID: string;
|
ID: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -55,12 +55,12 @@ const EditDialog = () => {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
const [formField, setFormField] = useState(initialStateConversion);
|
||||||
const updated_time = new Date();
|
const updated_time = new Date();
|
||||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateConversion);
|
||||||
setErrors({});
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ const EditDialog = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
|
|
||||||
if (!validateForm(formField, setErrors)) {
|
if (!validateFormConversion(formField, setErrors)) {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
export const validateForm = (formField: any, setErrors: any) => {
|
export const validateFormConversion = (
|
||||||
|
formField: typeof initialStateConversion,
|
||||||
|
setErrors: React.Dispatch<React.SetStateAction<Record<string, string>>>
|
||||||
|
) => {
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
{ key: 'id_currency_origin', label: 'Currency Origin' },
|
{ key: 'id_currency_origin', label: 'Currency Origin' },
|
||||||
{ key: 'id_currency_destination', label: 'Currency Destination' },
|
{ key: 'id_currency_destination', label: 'Currency Destination' },
|
||||||
@ -28,7 +31,7 @@ export const validateForm = (formField: any, setErrors: any) => {
|
|||||||
return isValid;
|
return isValid;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialState: {
|
export const initialStateConversion: {
|
||||||
status: string;
|
status: string;
|
||||||
id_currency_origin: string;
|
id_currency_origin: string;
|
||||||
id_currency_destination: string;
|
id_currency_destination: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user