Skip to content

Commit

Permalink
feat: add address modify
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghanzhilian committed Dec 26, 2023
1 parent 9df30c3 commit 56d3719
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/(main)/(client-layout)/checkout/shipping/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ShippingPage = () => {
if (
!userInfo?.address?.city &&
!userInfo?.address?.province &&
!userInfo?.address?.area &&
!userInfo?.address?.street &&
!userInfo?.address?.postalCode
)
Expand Down Expand Up @@ -101,7 +102,7 @@ const ShippingPage = () => {
isError={isError}
isSuccess={isSuccess}
error={error}
message={data?.msg}
message={data?.data?.message}
onSuccess={() => {
dispatch(clearCart())
router.push('/profile')
Expand Down
24 changes: 13 additions & 11 deletions components/modals/AddressModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ const AddressModal = props => {

//? Re-Renders
//* Change cities beside on province
useEffect(() => {
setValue('area', {})
getValues('city')?.code ? setAreas(regions.getAreasByCity(getValues('city')?.code)) : ''
watch('city')
}, [getValues('city')?.code])

useEffect(() => {
setValue('city', {})
setCities(regions.getCitysByProvince(getValues('province')?.code))
watch('province')
}, [getValues('province')?.code])

useEffect(() => {
setValue('area', {})

setAreas(regions.getAreasByCity(getValues('city')?.code))
watch('city')
}, [getValues('city')?.code])

useEffect(() => {
if (userInfo?.address) setValue('city', userInfo.address.city)
if (userInfo?.address) {
setValue('city', userInfo.address.city)
setValue('area', userInfo.address.area)
}
}, [])

//? Handlers
Expand All @@ -84,8 +86,8 @@ const AddressModal = props => {
<HandleResponse
isError={isError}
isSuccess={isSuccess}
error={error}
message={data?.msg}
error={error?.data?.message}
message={data?.message}
onSuccess={onClose}
/>
)}
Expand All @@ -102,7 +104,7 @@ const AddressModal = props => {
className="flex flex-col justify-between flex-1 pl-4 overflow-y-auto"
onSubmit={handleSubmit(submitHander)}
>
<div className="max-w-xl space-y-12 md:grid md:grid-cols-2 md:gap-x-12 md:gap-y-5 md:items-baseline ">
<div className="space-y-12 md:grid md:grid-cols-3 md:gap-x-12 md:gap-y-5 md:items-baseline ">
<div className="space-y-2">
<Combobox
control={control}
Expand Down
2 changes: 1 addition & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const UserSchema = new mongoose.Schema({
},
},
province: {
id: {
code: {
type: String,
},
name: {
Expand Down

0 comments on commit 56d3719

Please sign in to comment.