fix form field to match with response
This commit is contained in:
@ -24,8 +24,8 @@ import {
|
|||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
|
|
||||||
interface ProviderProps {
|
interface ProviderProps {
|
||||||
id: number;
|
provider_id: number;
|
||||||
name: string;
|
provider_name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
@ -40,17 +40,17 @@ const AddDialog = () => {
|
|||||||
message: ''
|
message: ''
|
||||||
});
|
});
|
||||||
const initialState = {
|
const initialState = {
|
||||||
name: '',
|
products_name: '',
|
||||||
code: '',
|
products_code: '',
|
||||||
type: '',
|
products_type: '',
|
||||||
description: '',
|
products_description: '',
|
||||||
price_point: 0,
|
products_price_point: 0,
|
||||||
price_cash: 0,
|
products_price_cash: 0,
|
||||||
cashback_point: 0,
|
products_cashback_point: 0,
|
||||||
cashback_cash: 0,
|
products_cashback_cash: 0,
|
||||||
status: '',
|
products_status: '',
|
||||||
provider: '',
|
products_provider: '',
|
||||||
process_on_third_party: '',
|
products_process_on_third_party: '',
|
||||||
created_by: '',
|
created_by: '',
|
||||||
created_at: ''
|
created_at: ''
|
||||||
};
|
};
|
||||||
@ -104,15 +104,15 @@ const AddDialog = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
formField.name.trim() === '' ||
|
formField.products_name.trim() === '' ||
|
||||||
formField.type.trim() === '' ||
|
formField.products_type.trim() === '' ||
|
||||||
formField.code.trim() === '' ||
|
formField.products_code.trim() === '' ||
|
||||||
formField.description.trim() === '' ||
|
formField.products_description.trim() === '' ||
|
||||||
formField.price_point === 0 ||
|
formField.products_price_point === 0 ||
|
||||||
formField.price_cash === 0 ||
|
formField.products_price_cash === 0 ||
|
||||||
formField.cashback_point === 0 ||
|
formField.products_cashback_point === 0 ||
|
||||||
formField.cashback_cash === 0 ||
|
formField.products_cashback_cash === 0 ||
|
||||||
formField.status.trim() === '' ||
|
formField.products_status.trim() === '' ||
|
||||||
formField.created_by.trim() === '' ||
|
formField.created_by.trim() === '' ||
|
||||||
formField.created_at.trim() === ''
|
formField.created_at.trim() === ''
|
||||||
) {
|
) {
|
||||||
@ -152,7 +152,7 @@ const AddDialog = () => {
|
|||||||
<DialogTitle>Product - Create</DialogTitle>
|
<DialogTitle>Product - Create</DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription></DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef} className='overflow-y-auto'>
|
<DialogBody ref={parentRef} className="overflow-y-auto">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && (
|
{alert.show && (
|
||||||
<Alert variant="danger">
|
<Alert variant="danger">
|
||||||
@ -170,8 +170,10 @@ const AddDialog = () => {
|
|||||||
<Input
|
<Input
|
||||||
className="input"
|
className="input"
|
||||||
type="text"
|
type="text"
|
||||||
value={formField.name}
|
value={formField.products_name}
|
||||||
onChange={(e) => setFormField({ ...formField, name: e.target.value })}
|
onChange={(e) =>
|
||||||
|
setFormField({ ...formField, products_name: e.target.value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -184,8 +186,10 @@ const AddDialog = () => {
|
|||||||
<Input
|
<Input
|
||||||
className="input"
|
className="input"
|
||||||
type="text"
|
type="text"
|
||||||
value={formField.type}
|
value={formField.products_type}
|
||||||
onChange={(e) => setFormField({ ...formField, type: e.target.value })}
|
onChange={(e) =>
|
||||||
|
setFormField({ ...formField, products_type: e.target.value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -198,8 +202,10 @@ const AddDialog = () => {
|
|||||||
<Input
|
<Input
|
||||||
className="input"
|
className="input"
|
||||||
type="text"
|
type="text"
|
||||||
value={formField.code}
|
value={formField.products_code}
|
||||||
onChange={(e) => setFormField({ ...formField, code: e.target.value })}
|
onChange={(e) =>
|
||||||
|
setFormField({ ...formField, products_code: e.target.value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -212,8 +218,10 @@ const AddDialog = () => {
|
|||||||
<Input
|
<Input
|
||||||
className="input"
|
className="input"
|
||||||
type="text"
|
type="text"
|
||||||
value={formField.description}
|
value={formField.products_description}
|
||||||
onChange={(e) => setFormField({ ...formField, description: e.target.value })}
|
onChange={(e) =>
|
||||||
|
setFormField({ ...formField, products_description: e.target.value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -228,10 +236,13 @@ const AddDialog = () => {
|
|||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
step={0.01}
|
step={0.01}
|
||||||
value={formField.price_point}
|
value={formField.products_price_point}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = parseFloat(e.target.value);
|
const value = parseFloat(e.target.value);
|
||||||
setFormField({ ...formField, price_point: isNaN(value) ? 0 : value });
|
setFormField({
|
||||||
|
...formField,
|
||||||
|
products_price_point: isNaN(value) ? 0 : value
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -247,10 +258,13 @@ const AddDialog = () => {
|
|||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
step={0.01}
|
step={0.01}
|
||||||
value={formField.price_cash}
|
value={formField.products_price_cash}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = parseFloat(e.target.value);
|
const value = parseFloat(e.target.value);
|
||||||
setFormField({ ...formField, price_cash: isNaN(value) ? 0 : value });
|
setFormField({
|
||||||
|
...formField,
|
||||||
|
products_price_cash: isNaN(value) ? 0 : value
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -266,10 +280,13 @@ const AddDialog = () => {
|
|||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
step={0.01}
|
step={0.01}
|
||||||
value={formField.cashback_point}
|
value={formField.products_cashback_point}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = parseFloat(e.target.value);
|
const value = parseFloat(e.target.value);
|
||||||
setFormField({ ...formField, cashback_point: isNaN(value) ? 0 : value });
|
setFormField({
|
||||||
|
...formField,
|
||||||
|
products_cashback_point: isNaN(value) ? 0 : value
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -285,10 +302,13 @@ const AddDialog = () => {
|
|||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
step={0.01}
|
step={0.01}
|
||||||
value={formField.cashback_cash}
|
value={formField.products_cashback_cash}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = parseFloat(e.target.value);
|
const value = parseFloat(e.target.value);
|
||||||
setFormField({ ...formField, cashback_cash: isNaN(value) ? 0 : value });
|
setFormField({
|
||||||
|
...formField,
|
||||||
|
products_cashback_cash: isNaN(value) ? 0 : value
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -300,8 +320,10 @@ const AddDialog = () => {
|
|||||||
Status<span className="text-red-500">*</span>
|
Status<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.products_status}
|
||||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
onValueChange={(value) =>
|
||||||
|
setFormField({ ...formField, products_status: value })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Select Status" />
|
<SelectValue placeholder="Select Status" />
|
||||||
@ -320,9 +342,9 @@ const AddDialog = () => {
|
|||||||
Provider ID
|
Provider ID
|
||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.provider}
|
value={formField.products_provider}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setFormField({ ...formField, provider: value.toString() })
|
setFormField({ ...formField, products_provider: value.toString() })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
@ -330,8 +352,11 @@ const AddDialog = () => {
|
|||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{providers.map((provider) => (
|
{providers.map((provider) => (
|
||||||
<SelectItem key={provider.id} value={provider.id.toString()}>
|
<SelectItem
|
||||||
{provider.name}
|
key={provider.provider_id}
|
||||||
|
value={provider.provider_id.toString()}
|
||||||
|
>
|
||||||
|
{provider.provider_name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
@ -345,9 +370,9 @@ const AddDialog = () => {
|
|||||||
Process on Third Party<span className="text-red-500">*</span>
|
Process on Third Party<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.process_on_third_party}
|
value={formField.products_process_on_third_party}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setFormField({ ...formField, process_on_third_party: value })
|
setFormField({ ...formField, products_process_on_third_party: value })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
|
|||||||
@ -24,8 +24,8 @@ import {
|
|||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
|
|
||||||
interface ProviderProps {
|
interface ProviderProps {
|
||||||
id: string;
|
provider_id: string;
|
||||||
name: string;
|
provider_name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
@ -114,7 +114,7 @@ const EditDialog = () => {
|
|||||||
cashback_point: response.data.cashback_point,
|
cashback_point: response.data.cashback_point,
|
||||||
cashback_cash: response.data.cashback_cash,
|
cashback_cash: response.data.cashback_cash,
|
||||||
status: response.data.status,
|
status: response.data.status,
|
||||||
provider: response.data.provider_id,
|
provider: response.data.provider.id,
|
||||||
process_on_third_party: response.data.process_on_third_party
|
process_on_third_party: response.data.process_on_third_party
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
@ -356,8 +356,8 @@ const EditDialog = () => {
|
|||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{providers.map((provider) => (
|
{providers.map((provider) => (
|
||||||
<SelectItem key={provider.id} value={provider.id}>
|
<SelectItem key={provider.provider_id} value={provider.provider_id}>
|
||||||
{provider.name}
|
{provider.provider_name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|||||||
@ -7,12 +7,12 @@ import { Toaster } from 'sonner';
|
|||||||
import ListToolbar from '../blocks/ListToolbar';
|
import ListToolbar from '../blocks/ListToolbar';
|
||||||
|
|
||||||
interface ProductsProps {
|
interface ProductsProps {
|
||||||
name: string;
|
products_name: string;
|
||||||
description: string;
|
products_description: string;
|
||||||
price_point: number;
|
products_price_point: number;
|
||||||
price_cash: number;
|
products_price_cash: number;
|
||||||
status: string;
|
products_status: string;
|
||||||
providerId: string;
|
products_providerId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContextProps {
|
interface ContextProps {
|
||||||
@ -73,7 +73,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
const columns = useMemo<ColumnDef<any>[]>(
|
const columns = useMemo<ColumnDef<any>[]>(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
accessorFn: (row) => row.id,
|
accessorFn: (row) => row.products_id,
|
||||||
id: 'id',
|
id: 'id',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="ID" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="ID" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
@ -83,7 +83,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => row.name,
|
accessorFn: (row) => row.products_name,
|
||||||
id: 'name',
|
id: 'name',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
@ -93,7 +93,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => row.description,
|
accessorFn: (row) => row.products_description,
|
||||||
id: 'description',
|
id: 'description',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
@ -103,7 +103,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => row.price_point,
|
accessorFn: (row) => row.products_price_point,
|
||||||
id: 'price_point',
|
id: 'price_point',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Price Point" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Price Point" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
@ -113,7 +113,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => row.price_cash,
|
accessorFn: (row) => row.products_price_cash,
|
||||||
id: 'price_cash',
|
id: 'price_cash',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Price Cash" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Price Cash" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
@ -133,13 +133,13 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||||
onClick={() => handleEditDialog(true, row.id)}
|
onClick={() => handleEditDialog(true, row.products_id)}
|
||||||
>
|
>
|
||||||
<KeenIcon icon="notepad-edit" />
|
<KeenIcon icon="notepad-edit" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||||
onClick={() => handleDeleteDialog(true, row.id)}
|
onClick={() => handleDeleteDialog(true, row.products_id)}
|
||||||
>
|
>
|
||||||
<KeenIcon icon="trash" />
|
<KeenIcon icon="trash" />
|
||||||
</button>
|
</button>
|
||||||
@ -167,7 +167,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
|
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
|
||||||
filter: JSON.stringify(filter)
|
filter: JSON.stringify(filter)
|
||||||
});
|
});
|
||||||
// console.log(response?.data);
|
console.log(response?.data);
|
||||||
setProducts(response?.data.list);
|
setProducts(response?.data.list);
|
||||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user