update field agent to optional on Provider

This commit is contained in:
Wikzyy
2025-04-10 11:09:33 +07:00
parent ebd11d082e
commit 07dfcf6074
2 changed files with 145 additions and 102 deletions

View File

@ -61,7 +61,17 @@ const AddDialog = () => {
show: false, show: false,
message: '' message: ''
}); });
const initialState = {
const initialState: {
name: string;
description: string;
type: string;
status: string;
transaction_type: string;
agent: string;
created_by: string;
created_at: string;
} = {
name: '', name: '',
description: '', description: '',
type: '', type: '',
@ -71,6 +81,7 @@ const AddDialog = () => {
created_by: '', created_by: '',
created_at: '' created_at: ''
}; };
const [formField, setFormField] = useState(initialState); const [formField, setFormField] = useState(initialState);
const [customers, setCustomers] = useState<CustomerProps[]>([]); const [customers, setCustomers] = useState<CustomerProps[]>([]);
const [transactions, setTransactions] = useState<TransactionProps[]>([]); const [transactions, setTransactions] = useState<TransactionProps[]>([]);
@ -116,8 +127,7 @@ const AddDialog = () => {
formField.description.trim() === '' || formField.description.trim() === '' ||
formField.type.trim() === '' || formField.type.trim() === '' ||
formField.status.trim() === '' || formField.status.trim() === '' ||
formField.transaction_type === '' || formField.transaction_type === ''
formField.agent.trim() === ''
) { ) {
setAlert({ show: true, message: 'Please fill in all required fields.' }); setAlert({ show: true, message: 'Please fill in all required fields.' });
return; return;
@ -242,7 +252,7 @@ const AddDialog = () => {
<SelectValue placeholder="Select Type" /> <SelectValue placeholder="Select Type" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="h2h">H2H</SelectItem> <SelectItem value="h2h">Host to Host</SelectItem>
<SelectItem value="agent">Agent</SelectItem> <SelectItem value="agent">Agent</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
@ -294,6 +304,7 @@ const AddDialog = () => {
</div> </div>
</div> </div>
{formField.type === 'agent' ? (
<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">
@ -344,6 +355,16 @@ const AddDialog = () => {
</Popover> </Popover>
</div> </div>
</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">
Agent Name<span className="text-red-500">*</span>
</label>
<Input type="text" placeholder="Type Agent Only" readOnly />
</div>
</div>
)}
<div className="flex justify-end gap-5"> <div className="flex justify-end gap-5">
<Button type="button" variant="outline" onClick={resetForm}> <Button type="button" variant="outline" onClick={resetForm}>

View File

@ -51,7 +51,17 @@ const EditDialog = () => {
show: false, show: false,
message: '' message: ''
}); });
const initialState = {
const initialState: {
name: string;
description: string;
type: string;
status: string;
transaction_type: string;
agent: string;
updated_by: string;
updated_at: string;
} = {
name: '', name: '',
description: '', description: '',
type: '', type: '',
@ -61,6 +71,7 @@ const EditDialog = () => {
updated_by: '', updated_by: '',
updated_at: '' updated_at: ''
}; };
const [formField, setFormField] = useState(initialState); const [formField, setFormField] = useState(initialState);
const [transactions, setTransactions] = useState<TransactionProps[]>([]); const [transactions, setTransactions] = useState<TransactionProps[]>([]);
const [customers, setCustomers] = useState<CustomerProps[]>([]); const [customers, setCustomers] = useState<CustomerProps[]>([]);
@ -257,7 +268,7 @@ const EditDialog = () => {
<SelectValue placeholder="Select Type" /> <SelectValue placeholder="Select Type" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="h2h">H2H</SelectItem> <SelectItem value="h2h">Host to Host</SelectItem>
<SelectItem value="agent">Agent</SelectItem> <SelectItem value="agent">Agent</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
@ -309,6 +320,7 @@ const EditDialog = () => {
</div> </div>
</div> </div>
{formField.type === 'agent' ? (
<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">
@ -322,7 +334,7 @@ const EditDialog = () => {
style={{ color: 'inherit' }} style={{ color: 'inherit' }}
> >
{customers.find((customer) => customer.id === formField.agent) {customers.find((customer) => customer.id === formField.agent)
?.fullname || 'Select Agent'} ?.username || 'Select Agent'}
</button> </button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent className="w-[400px] p-0"> <PopoverContent className="w-[400px] p-0">
@ -349,7 +361,7 @@ const EditDialog = () => {
setOpen(false); setOpen(false);
}} }}
> >
{customer.fullname} {customer.username}
</CommandItem> </CommandItem>
))} ))}
</CommandGroup> </CommandGroup>
@ -359,6 +371,16 @@ const EditDialog = () => {
</Popover> </Popover>
</div> </div>
</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">
Agent Name<span className="text-red-500">*</span>
</label>
<Input type="text" placeholder="Type Agent Only" readOnly />
</div>
</div>
)}
<div className="flex justify-end"> <div className="flex justify-end">
<Button variant="default">Save Changes</Button> <Button variant="default">Save Changes</Button>