From 1739c6eb03631e08bfe9d5de3a97acbc0a8566ce Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 13 Jan 2023 15:36:28 +0700 Subject: create "edit" feature and fix "create" feature --- src/pages/my/address/create.js | 248 +++++++++++++++++++++-------------------- 1 file changed, 125 insertions(+), 123 deletions(-) (limited to 'src/pages/my/address/create.js') diff --git a/src/pages/my/address/create.js b/src/pages/my/address/create.js index d68d1f76..457429e3 100644 --- a/src/pages/my/address/create.js +++ b/src/pages/my/address/create.js @@ -8,6 +8,7 @@ import { useAuth } from "../../../helpers/auth"; import useFormValidation from "../../../helpers/formValidation"; import { toast } from "react-hot-toast"; import { useRouter } from "next/router"; +import _ from "lodash"; const initialFormValue = { type: null, @@ -31,6 +32,13 @@ const validationScheme = { zip: ['label:Kode Pos', 'required'] }; +const typesSelection = [ + { value: 'contact', label: 'Contact Address' }, + { value: 'invoice', label: 'Invoice Address' }, + { value: 'delivery', label: 'Delivery Address' }, + { value: 'other', label: 'Other Address' }, +]; + export default function CreateAddress() { const [auth] = useAuth(); const router = useRouter(); @@ -85,13 +93,6 @@ export default function CreateAddress() { } }, [ formInputs.district, handleSelectChange ]); - const addressTypes = [ - { value: 'contact', label: 'Contact Address' }, - { value: 'invoice', label: 'Invoice Address' }, - { value: 'delivery', label: 'Delivery Address' }, - { value: 'other', label: 'Other Address' }, - ]; - const onSubmit = async () => { const parameters = { ...formInputs, @@ -99,15 +100,14 @@ export default function CreateAddress() { district_id: formInputs.district?.value, sub_district_id: formInputs.subDistrict?.value, type: formInputs.type?.value, - user_id: auth.id, - partner_id: auth.partner_id, + parent_id: auth.partner_id, }; - const address = await apiOdoo('POST', '/api/v1/partner', parameters); + const address = await apiOdoo('POST', '/api/v1/partner/address', parameters); if (address?.id) { handleFormReset(); toast.success('Berhasil menambahkan alamat'); - router.push('/my/address'); + router.back(); } } @@ -116,118 +116,120 @@ export default function CreateAddress() { -
handleFormSubmit(e, onSubmit)}> - - handleSelectChange('type', value)} - value={formInputs?.type} - /> -
{formErrors?.type}
- - - -
{formErrors?.name}
- - - -
{formErrors?.email}
- - - -
{formErrors?.mobile}
- - - -
{formErrors?.street}
- - - state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }} - options={cities} - value={formInputs.city} - onChange={(value) => handleSelectChange('city', value)} - /> -
{formErrors?.city}
- - - state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }} - options={districts} - value={formInputs.district} - onChange={(value) => handleSelectChange('district', value)} - isDisabled={!formInputs.city} - /> - - - state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }} - options={subDistricts} - onChange={(value) => handleSelectChange('subDistrict', value)} - value={formInputs.subDistrict} - isDisabled={!formInputs.district} - /> - - - -
{formErrors?.zip}
- - - + { !_.isEmpty(formInputs) && ( +
handleFormSubmit(e, onSubmit)}> + + handleSelectChange('type', value)} + value={formInputs?.type} + /> +
{formErrors?.type}
+ + + +
{formErrors?.name}
+ + + +
{formErrors?.email}
+ + + +
{formErrors?.mobile}
+ + + +
{formErrors?.street}
+ + + +
{formErrors?.zip}
+ + + state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }} + options={cities} + value={formInputs.city} + onChange={(value) => handleSelectChange('city', value)} + /> +
{formErrors?.city}
+ + + state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }} + options={districts} + value={formInputs.district} + onChange={(value) => handleSelectChange('district', value)} + isDisabled={!formInputs.city} + /> + + + state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }} + options={subDistricts} + onChange={(value) => handleSelectChange('subDistrict', value)} + value={formInputs.subDistrict} + isDisabled={!formInputs.district} + /> + + + + ) }
); -- cgit v1.2.3