fix create Product

- add validation input cannot be empty
This commit is contained in:
Wikzyy
2025-04-10 17:50:48 +07:00
parent 59d74d4304
commit bb42f87dcc

View File

@ -23,6 +23,7 @@ import {
SelectValue SelectValue
} from '@/components/ui/select'; } from '@/components/ui/select';
import { doSaveLogActivity } from '@/actions/GlobalActions'; import { doSaveLogActivity } from '@/actions/GlobalActions';
import { NumericFormat } from 'react-number-format';
interface ProviderProps { interface ProviderProps {
provider_id: number; provider_id: number;
@ -40,15 +41,29 @@ const AddDialog = () => {
show: false, show: false,
message: '' message: ''
}); });
const initialState = { const initialState: {
name: string;
code: string;
type: string;
description: string;
price_point: string | number | null;
price_cash: string | number | null;
cashback_point: string | number | null;
cashback_cash: string | number | null;
status: string;
provider: string;
process_on_third_party: string;
created_by: string;
created_at: string;
} = {
name: '', name: '',
code: '', code: '',
type: '', type: '',
description: '', description: '',
price_point: 0, price_point: null,
price_cash: 0, price_cash: null,
cashback_point: 0, cashback_point: null,
cashback_cash: 0, cashback_cash: null,
status: '', status: '',
provider: '', provider: '',
process_on_third_party: '', process_on_third_party: '',
@ -117,11 +132,13 @@ const AddDialog = () => {
formField.type.trim() === '' || formField.type.trim() === '' ||
formField.code.trim() === '' || formField.code.trim() === '' ||
formField.description.trim() === '' || formField.description.trim() === '' ||
formField.price_point === 0 || formField.price_point === null ||
formField.price_cash === 0 || formField.price_cash === null ||
formField.cashback_point === 0 || formField.cashback_point === null ||
formField.cashback_cash === 0 || formField.cashback_cash === null ||
formField.status.trim() === '' || formField.status.trim() === '' ||
formField.provider.trim() === '' ||
formField.process_on_third_party.trim() === '' ||
formField.created_by.trim() === '' || formField.created_by.trim() === '' ||
formField.created_at.trim() === '' formField.created_at.trim() === ''
) { ) {
@ -234,19 +251,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56"> <label className="form-label flex items-center gap-1 max-w-56">
Price Point<span className="text-red-500">*</span> Price Point<span className="text-red-500">*</span>
</label> </label>
<Input <NumericFormat
className="input" className="input"
type="number" value={formField.price_point ?? ''}
min={0} thousandSeparator="."
step={0.01} decimalSeparator=","
value={formField.price_point} allowNegative={false}
onChange={(e) => { onValueChange={(values) => {
const value = parseFloat(e.target.value); setFormField((prev) => ({
setFormField({ ...prev,
...formField, price_point: values.floatValue !== undefined ? values.floatValue : ''
price_point: isNaN(value) ? 0 : value }));
});
}} }}
placeholder="Enter Price Point"
/> />
</div> </div>
</div> </div>
@ -256,19 +273,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56"> <label className="form-label flex items-center gap-1 max-w-56">
Price Cash<span className="text-red-500">*</span> Price Cash<span className="text-red-500">*</span>
</label> </label>
<Input <NumericFormat
className="input" className="input"
type="number" value={formField.price_cash ?? ''}
min={0} thousandSeparator="."
step={0.01} decimalSeparator=","
value={formField.price_cash} allowNegative={false}
onChange={(e) => { onValueChange={(values) => {
const value = parseFloat(e.target.value); setFormField((prev) => ({
setFormField({ ...prev,
...formField, price_cash: values.floatValue !== undefined ? values.floatValue : ''
price_cash: isNaN(value) ? 0 : value }));
});
}} }}
placeholder="Enter Price Cash"
/> />
</div> </div>
</div> </div>
@ -278,19 +295,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56"> <label className="form-label flex items-center gap-1 max-w-56">
Cashback Point<span className="text-red-500">*</span> Cashback Point<span className="text-red-500">*</span>
</label> </label>
<Input <NumericFormat
className="input" className="input"
type="number" value={formField.cashback_point ?? ''}
min={0} thousandSeparator="."
step={0.01} decimalSeparator=","
value={formField.cashback_point} allowNegative={false}
onChange={(e) => { onValueChange={(values) => {
const value = parseFloat(e.target.value); setFormField((prev) => ({
setFormField({ ...prev,
...formField, cashback_point: values.floatValue !== undefined ? values.floatValue : ''
cashback_point: isNaN(value) ? 0 : value }));
});
}} }}
placeholder="Enter Cashback Point"
/> />
</div> </div>
</div> </div>
@ -300,19 +317,19 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56"> <label className="form-label flex items-center gap-1 max-w-56">
Cashback Cash<span className="text-red-500">*</span> Cashback Cash<span className="text-red-500">*</span>
</label> </label>
<Input <NumericFormat
className="input" className="input"
type="number" value={formField.cashback_cash ?? ''}
min={0} thousandSeparator="."
step={0.01} decimalSeparator=","
value={formField.cashback_cash} allowNegative={false}
onChange={(e) => { onValueChange={(values) => {
const value = parseFloat(e.target.value); setFormField((prev) => ({
setFormField({ ...prev,
...formField, cashback_cash: values.floatValue !== undefined ? values.floatValue : ''
cashback_cash: isNaN(value) ? 0 : value }));
});
}} }}
placeholder="Enter Cashback Cash"
/> />
</div> </div>
</div> </div>