refactor: form access type
This commit is contained in:
@ -21,22 +21,11 @@ import {
|
|||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
interface CreateTransferTypeParams {
|
|
||||||
transfer_type_name: string;
|
|
||||||
description: string;
|
|
||||||
from_account: string;
|
|
||||||
to_account: string;
|
|
||||||
minimal_amount: number;
|
|
||||||
maximum_amount: number;
|
|
||||||
otp_threshold: number;
|
|
||||||
maximum_transaction_perDay: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const API_URL = apiConfig.service_dashboard;
|
const API_URL = apiConfig.service_dashboard;
|
||||||
|
|
||||||
const AddDialog = () => {
|
const AddDialog = () => {
|
||||||
const parentRef = useRef<any | null>(null);
|
const parentRef = useRef<any | null>(null);
|
||||||
const { showAddDialog, handleAddDialog, accounts } = useManageAccessTypeContext();
|
const { showAddDialog, handleAddDialog, accessTypes } = useManageAccessTypeContext();
|
||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { PostData, PutData } = useCallApi();
|
const { PostData, PutData } = useCallApi();
|
||||||
const [alert, setAlert] = useState({
|
const [alert, setAlert] = useState({
|
||||||
@ -45,14 +34,9 @@ const AddDialog = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
transfer_type_name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
from_account: '',
|
internal_name: ''
|
||||||
to_account: '',
|
|
||||||
minimal_amount: 0,
|
|
||||||
maximum_amount: 0,
|
|
||||||
otp_threshold: 0,
|
|
||||||
maximum_transaction_perDay: 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
const [formField, setFormField] = useState(initialState);
|
||||||
@ -64,17 +48,11 @@ const AddDialog = () => {
|
|||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// setIsSubmitting(true);
|
// setIsSubmitting(true);
|
||||||
const payload = {
|
console.log(formField);
|
||||||
transfer_type_name: formField.transfer_type_name,
|
};
|
||||||
description: formField.description,
|
|
||||||
from_account: formField.from_account,
|
const handleReset = () => {
|
||||||
to_account: formField.to_account,
|
setFormField(initialState);
|
||||||
minimal_amount: formField.minimal_amount,
|
|
||||||
maximum_amount: formField.maximum_amount,
|
|
||||||
otp_threshold: formField.otp_threshold,
|
|
||||||
maximum_transaction_perDay: formField.maximum_transaction_perDay
|
|
||||||
};
|
|
||||||
console.log(payload);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -84,7 +62,7 @@ const AddDialog = () => {
|
|||||||
<div className="flex items-center justify-between flex-wrap grow">
|
<div className="flex items-center justify-between flex-wrap grow">
|
||||||
<div className="flex flex-col justify-center">
|
<div className="flex flex-col justify-center">
|
||||||
<h1 className="text-xl font-semibold leading-none text-gray-900">
|
<h1 className="text-xl font-semibold leading-none text-gray-900">
|
||||||
Create Transfer Type
|
Create Access Type
|
||||||
</h1>
|
</h1>
|
||||||
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
|
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
|
||||||
</div>
|
</div>
|
||||||
@ -110,16 +88,14 @@ const AddDialog = () => {
|
|||||||
<div className="card-body grid gap-5 p-0">
|
<div className="card-body grid gap-5 p-0">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
<label className="form-label flex items-center gap-1 max-w-56">Name</label>
|
||||||
Transfer Type Name
|
|
||||||
</label>
|
|
||||||
<Input
|
<Input
|
||||||
className="input"
|
className="input"
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.transfer_type_name}
|
value={formField.name}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) =>
|
||||||
setFormField((prev) => ({ ...prev, transfer_type_name: target.value }))
|
setFormField((prev) => ({ ...prev, name: target.value }))
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -142,140 +118,25 @@ const AddDialog = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<div className="flex items-center flex-wrap gap-2.5">
|
|
||||||
<label className="form-label max-w-56">From Account</label>
|
|
||||||
|
|
||||||
<div className="grow">
|
|
||||||
<Select
|
|
||||||
value={formField.from_account}
|
|
||||||
onValueChange={(target) =>
|
|
||||||
setFormField((prev) => ({ ...prev, from_account: target }))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<SelectTrigger>
|
|
||||||
<SelectValue placeholder="Select" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{accounts.map((account, idx) => (
|
|
||||||
<SelectItem value={account.name} key={account.id}>
|
|
||||||
{account.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<div className="flex items-center flex-wrap gap-2.5">
|
|
||||||
<label className="form-label max-w-56">To Account</label>
|
|
||||||
|
|
||||||
<div className="grow">
|
|
||||||
<Select
|
|
||||||
value={formField.to_account}
|
|
||||||
onValueChange={(target) =>
|
|
||||||
setFormField((prev) => ({ ...prev, to_account: target }))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<SelectTrigger>
|
|
||||||
<SelectValue placeholder="Select" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{accounts.map((account, idx) => (
|
|
||||||
<SelectItem value={account.name} key={account.id}>
|
|
||||||
{account.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
<label className="form-label flex items-center gap-1 max-w-56">
|
||||||
Minimal Amount
|
Internal Name
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
className="input"
|
className="input"
|
||||||
type="number"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.minimal_amount}
|
value={formField.internal_name}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) =>
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({ ...prev, internal_name: target.value }))
|
||||||
...prev,
|
|
||||||
minimal_amount: Number(target.value)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
|
||||||
Maximum Amount
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
className="input"
|
|
||||||
type="number"
|
|
||||||
autoComplete="off"
|
|
||||||
value={formField.maximum_amount}
|
|
||||||
onChange={({ target }) =>
|
|
||||||
setFormField((prev) => ({
|
|
||||||
...prev,
|
|
||||||
maximum_amount: Number(target.value)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
|
||||||
OTP Threshold
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
className="input"
|
|
||||||
type="number"
|
|
||||||
autoComplete="off"
|
|
||||||
value={formField.otp_threshold}
|
|
||||||
onChange={({ target }) =>
|
|
||||||
setFormField((prev) => ({
|
|
||||||
...prev,
|
|
||||||
otp_threshold: Number(target.value)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="w-full">
|
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
|
||||||
Maximum Transaction / day
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
className="input"
|
|
||||||
type="number"
|
|
||||||
autoComplete="off"
|
|
||||||
value={formField.maximum_transaction_perDay}
|
|
||||||
onChange={({ target }) =>
|
|
||||||
setFormField((prev) => ({
|
|
||||||
...prev,
|
|
||||||
maximum_transaction_perDay: Number(target.value)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end pt-2.5 gap-5">
|
<div className="flex justify-end pt-2.5 gap-5">
|
||||||
<Button variant={'outline'} type="reset">
|
<Button variant={'outline'} type="reset" onClick={handleReset}>
|
||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'default'} type="submit">
|
<Button variant={'default'} type="submit">
|
||||||
|
|||||||
@ -13,26 +13,20 @@ interface SelectedUser {
|
|||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AccountProps {
|
interface AccessTypeProps {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
internal_name: string;
|
||||||
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const accounts: string[] = [
|
|
||||||
'eMoney Account',
|
|
||||||
'Topup Account',
|
|
||||||
'Merchant Account',
|
|
||||||
'Deposit Account',
|
|
||||||
'Cash out/in'
|
|
||||||
];
|
|
||||||
|
|
||||||
interface ContextProps {
|
interface ContextProps {
|
||||||
showEditDialog: boolean;
|
showEditDialog: boolean;
|
||||||
handleEditDialog: (show: boolean, selected_user: string | null) => void;
|
handleEditDialog: (show: boolean, selected_user: string | null) => void;
|
||||||
showAddDialog: boolean;
|
showAddDialog: boolean;
|
||||||
handleAddDialog: (show: boolean) => void;
|
handleAddDialog: (show: boolean) => void;
|
||||||
selectedUser: string | null;
|
selectedUser: string | null;
|
||||||
accounts: AccountProps[];
|
accessTypes: AccessTypeProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialProps: ContextProps = {
|
const initialProps: ContextProps = {
|
||||||
@ -41,7 +35,7 @@ const initialProps: ContextProps = {
|
|||||||
showAddDialog: false,
|
showAddDialog: false,
|
||||||
handleAddDialog: () => {},
|
handleAddDialog: () => {},
|
||||||
selectedUser: null,
|
selectedUser: null,
|
||||||
accounts: []
|
accessTypes: []
|
||||||
};
|
};
|
||||||
|
|
||||||
const ManageAccessTypeContext = createContext<ContextProps>(initialProps);
|
const ManageAccessTypeContext = createContext<ContextProps>(initialProps);
|
||||||
@ -51,19 +45,9 @@ const ManageAccessTypeContextProvider = ({ children }: { children: React.ReactNo
|
|||||||
const [showEditDialog, setShowEditDialog] = useState(false);
|
const [showEditDialog, setShowEditDialog] = useState(false);
|
||||||
const [showAddDialog, setShowAddDialog] = useState(false);
|
const [showAddDialog, setShowAddDialog] = useState(false);
|
||||||
const [selectedUser, setSelectedUser] = useState<string | null>(null);
|
const [selectedUser, setSelectedUser] = useState<string | null>(null);
|
||||||
const [accounts, setAccount] = useState<AccountProps[]>([]);
|
const [accessTypes, setAccessTypes] = useState<AccessTypeProps[]>([]);
|
||||||
const { GetData } = useCallApi();
|
const { GetData } = useCallApi();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setAccount([
|
|
||||||
{ id: '1', name: 'eMoney Account' },
|
|
||||||
{ id: '2', name: 'Topup Account' },
|
|
||||||
{ id: '3', name: 'Merchant Account' },
|
|
||||||
{ id: '4', name: 'Deposit Account' },
|
|
||||||
{ id: '5', name: 'Cash in/out Account' }
|
|
||||||
]);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleEditDialog = useCallback((show: boolean, selected_user: string | null) => {
|
const handleEditDialog = useCallback((show: boolean, selected_user: string | null) => {
|
||||||
setSelectedUser(show ? selected_user : null);
|
setSelectedUser(show ? selected_user : null);
|
||||||
setShowEditDialog(show);
|
setShowEditDialog(show);
|
||||||
@ -155,7 +139,7 @@ const ManageAccessTypeContextProvider = ({ children }: { children: React.ReactNo
|
|||||||
showAddDialog,
|
showAddDialog,
|
||||||
handleAddDialog,
|
handleAddDialog,
|
||||||
selectedUser,
|
selectedUser,
|
||||||
accounts
|
accessTypes
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Toaster expand visibleToasts={9} duration={3000} />
|
<Toaster expand visibleToasts={9} duration={3000} />
|
||||||
|
|||||||
Reference in New Issue
Block a user