summaryrefslogtreecommitdiff
path: root/src/pages/my/address/create.js
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-01-13 15:36:28 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-01-13 15:36:28 +0700
commit1739c6eb03631e08bfe9d5de3a97acbc0a8566ce (patch)
treea4e4e9c91059ed5bf68534892b851e22bcba195a /src/pages/my/address/create.js
parentcf69435c321eb6866caf75ed2a5391526f499c4e (diff)
create "edit" feature and fix "create" feature
Diffstat (limited to 'src/pages/my/address/create.js')
-rw-r--r--src/pages/my/address/create.js248
1 files changed, 125 insertions, 123 deletions
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() {
<Layout>
<AppBar title="Tambah Alamat" />
- <form className="px-4 pb-4" onSubmit={(e) => handleFormSubmit(e, onSubmit)}>
- <label className="form-label mt-4 mb-2">Label Alamat</label>
- <ReactSelect
- placeholder="Pilih label alamat..."
- classNamePrefix="form-select"
- options={addressTypes}
- name="type"
- onChange={(value) => handleSelectChange('type', value)}
- value={formInputs?.type}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.type}</div>
-
- <label className="form-label mt-4 mb-2">Nama Kontak</label>
- <input
- type="text"
- className='form-input'
- placeholder="John Doe"
- name="name"
- onChange={handleInputChange}
- value={formInputs.name}
- aria-invalid={formErrors?.name}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.name}</div>
-
- <label className="form-label mt-4 mb-2">Email</label>
- <input
- type="text"
- className='form-input'
- placeholder="johndoe@gmail.com"
- name="email"
- value={formInputs.email}
- onChange={handleInputChange}
- aria-invalid={formErrors?.email}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.email}</div>
-
- <label className="form-label mt-4 mb-2">No. Handphone</label>
- <input
- type="tel"
- className='form-input'
- placeholder="08xxxxxxxx"
- name="mobile"
- value={formInputs.mobile}
- onChange={handleInputChange}
- aria-invalid={formErrors?.mobile}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.mobile}</div>
-
- <label className="form-label mt-4 mb-2">Alamat</label>
- <input
- type="text"
- className='form-input'
- placeholder="Jl. Bandengan Utara"
- name="street"
- value={formInputs.street}
- onChange={handleInputChange}
- aria-invalid={formErrors?.street}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.street}</div>
-
- <label className="form-label mt-4 mb-2">Kota</label>
- <ReactSelect
- placeholder="Pilih kota..."
- classNamePrefix="form-select"
- classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
- options={cities}
- value={formInputs.city}
- onChange={(value) => handleSelectChange('city', value)}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.city}</div>
-
- <label className="form-label mt-4 mb-2">Kecamatan <span className="text-gray_r-11">(opsional)</span></label>
- <ReactSelect
- placeholder="Pilih Kecamatan..."
- classNamePrefix="form-select"
- classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
- options={districts}
- value={formInputs.district}
- onChange={(value) => handleSelectChange('district', value)}
- isDisabled={!formInputs.city}
- />
-
- <label className="form-label mt-4 mb-2">Kelurahan <span className="text-gray_r-11">(opsional)</span></label>
- <ReactSelect
- placeholder="Pilih Kelurahan..."
- classNamePrefix="form-select"
- classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
- options={subDistricts}
- onChange={(value) => handleSelectChange('subDistrict', value)}
- value={formInputs.subDistrict}
- isDisabled={!formInputs.district}
- />
-
- <label className="form-label mt-4 mb-2">Kode Pos</label>
- <input
- type="number"
- className='form-input'
- placeholder="10100"
- name="zip"
- value={formInputs.zip}
- onChange={handleInputChange}
- aria-invalid={formErrors?.zip}
- />
- <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.zip}</div>
-
- <button
- type="submit"
- className="btn-yellow mt-6 w-full"
- >
- Simpan
- </button>
- </form>
+ { !_.isEmpty(formInputs) && (
+ <form className="px-4 pb-4" onSubmit={(e) => handleFormSubmit(e, onSubmit)}>
+ <label className="form-label mt-4 mb-2">Label Alamat</label>
+ <ReactSelect
+ placeholder="Pilih label alamat..."
+ classNamePrefix="form-select"
+ options={typesSelection}
+ name="type"
+ onChange={(value) => handleSelectChange('type', value)}
+ value={formInputs?.type}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.type}</div>
+
+ <label className="form-label mt-4 mb-2">Nama Kontak</label>
+ <input
+ type="text"
+ className='form-input'
+ placeholder="John Doe"
+ name="name"
+ onChange={handleInputChange}
+ value={formInputs.name}
+ aria-invalid={formErrors?.name}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.name}</div>
+
+ <label className="form-label mt-4 mb-2">Email</label>
+ <input
+ type="text"
+ className='form-input'
+ placeholder="johndoe@gmail.com"
+ name="email"
+ value={formInputs.email}
+ onChange={handleInputChange}
+ aria-invalid={formErrors?.email}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.email}</div>
+
+ <label className="form-label mt-4 mb-2">No. Handphone</label>
+ <input
+ type="number"
+ className='form-input'
+ placeholder="08xxxxxxxx"
+ name="mobile"
+ value={formInputs.mobile}
+ onChange={handleInputChange}
+ aria-invalid={formErrors?.mobile}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.mobile}</div>
+
+ <label className="form-label mt-4 mb-2">Alamat</label>
+ <input
+ type="text"
+ className='form-input'
+ placeholder="Jl. Bandengan Utara"
+ name="street"
+ value={formInputs.street}
+ onChange={handleInputChange}
+ aria-invalid={formErrors?.street}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.street}</div>
+
+ <label className="form-label mt-4 mb-2">Kode Pos</label>
+ <input
+ type="number"
+ className='form-input'
+ placeholder="10100"
+ name="zip"
+ value={formInputs.zip}
+ onChange={handleInputChange}
+ aria-invalid={formErrors?.zip}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.zip}</div>
+
+ <label className="form-label mt-4 mb-2">Kota</label>
+ <ReactSelect
+ placeholder="Pilih kota..."
+ classNamePrefix="form-select"
+ classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
+ options={cities}
+ value={formInputs.city}
+ onChange={(value) => handleSelectChange('city', value)}
+ />
+ <div className="text-caption-2 text-red_r-11 mt-1">{formErrors?.city}</div>
+
+ <label className="form-label mt-4 mb-2">Kecamatan <span className="text-gray_r-10">(opsional)</span></label>
+ <ReactSelect
+ placeholder="Pilih Kecamatan..."
+ classNamePrefix="form-select"
+ classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
+ options={districts}
+ value={formInputs.district}
+ onChange={(value) => handleSelectChange('district', value)}
+ isDisabled={!formInputs.city}
+ />
+
+ <label className="form-label mt-4 mb-2">Kelurahan <span className="text-gray_r-10">(opsional)</span></label>
+ <ReactSelect
+ placeholder="Pilih Kelurahan..."
+ classNamePrefix="form-select"
+ classNames={{ control: (state) => state.menuIsOpen || state.isFocused ? '!border-yellow_r-9' : '' }}
+ options={subDistricts}
+ onChange={(value) => handleSelectChange('subDistrict', value)}
+ value={formInputs.subDistrict}
+ isDisabled={!formInputs.district}
+ />
+
+ <button
+ type="submit"
+ className="btn-yellow mt-6 w-full"
+ >
+ Simpan
+ </button>
+ </form>
+ ) }
</Layout>
</WithAuth>
);