-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update wishlist book and wishlist drawer with new account s…
…tructure feat(core): add delete wishlist mutation (#975) feat(core): add create wishlist mutation (#958) feat(core): update customer account modal component (#1001) feat(core): add wishlist items mutation (#1268) feat(core): delete wishlist items mutation (#1269) feat(core): update delete wishlists mutation (#1273) feat(core): update create wishlist mutation (#1272) feat(core): add wishlist book (#998) Add wishlist test (#1314) Update Wishlist test feat(core): add wishlist drawer (#1182)
- Loading branch information
1 parent
3176491
commit c28c716
Showing
41 changed files
with
1,640 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add delete wishlist mutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
update delete wishlists mutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add create wishlist mutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
delete wishlist items mutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
update customer account modal component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add wishlist book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add wishlist drawer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add wishlist items mutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
Add Wishlist test and update wishlist naming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
update create wishlist mutation because only minor data set is needed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...lt)/account/(tabs)/wishlists/_components/create-wishlist-form/_actions/create-wishlist.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use server'; | ||
|
||
import { revalidatePath } from 'next/cache'; | ||
import { z } from 'zod'; | ||
|
||
import { createWishlist as createWishlistMutation } from '~/client/mutations/create-wishlist'; | ||
|
||
const CreateWishlistSchema = z.object({ | ||
name: z.string(), | ||
}); | ||
|
||
export const createWishlist = async (formData: FormData) => { | ||
const parsedData = CreateWishlistSchema.parse({ | ||
name: formData.get('name'), | ||
}); | ||
|
||
const input = { | ||
...parsedData, | ||
isPublic: true, | ||
}; | ||
|
||
try { | ||
const newWishlist = await createWishlistMutation({ input }); | ||
|
||
revalidatePath('/account/wishlists', 'page'); | ||
|
||
if (newWishlist) { | ||
return { | ||
status: 'success' as const, | ||
data: newWishlist, | ||
}; | ||
} | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
return { | ||
status: 'error' as const, | ||
message: error.message, | ||
}; | ||
} | ||
} | ||
|
||
return { status: 'error' as const, message: 'Unknown error.' }; | ||
}; |
107 changes: 107 additions & 0 deletions
107
...pp/[locale]/(default)/account/(tabs)/wishlists/_components/create-wishlist-form/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import * as DialogPrimitive from '@radix-ui/react-alert-dialog'; | ||
import { useTranslations } from 'next-intl'; | ||
import { ChangeEvent, useState } from 'react'; | ||
import { useFormStatus } from 'react-dom'; | ||
|
||
import { createWishlist as createWishlistMutation } from '~/client/mutations/create-wishlist'; | ||
import { Button } from '~/components/ui/button'; | ||
import { | ||
Field, | ||
FieldControl, | ||
FieldLabel, | ||
FieldMessage, | ||
Form, | ||
FormSubmit, | ||
Input, | ||
} from '~/components/ui/form'; | ||
|
||
import { useAccountStatusContext } from '../../../_components/account-status-provider'; | ||
|
||
import { createWishlist } from './_actions/create-wishlist'; | ||
|
||
type Wishlist = NonNullable<Awaited<ReturnType<typeof createWishlistMutation>>>; | ||
|
||
interface CreateWishlistFormProps { | ||
onWishlistCreated: (newWishlist: Wishlist) => void; | ||
} | ||
|
||
const SubmitButton = () => { | ||
const { pending } = useFormStatus(); | ||
const t = useTranslations('Account.Wishlist'); | ||
|
||
return ( | ||
<Button | ||
className="relative w-full items-center px-8 py-2 lg:w-fit" | ||
loading={pending} | ||
loadingText={t('onSubmitText')} | ||
variant="primary" | ||
> | ||
{t('create')} | ||
</Button> | ||
); | ||
}; | ||
|
||
export const CreateWishlistForm = ({ onWishlistCreated }: CreateWishlistFormProps) => { | ||
const [isInputValid, setInputValidation] = useState(true); | ||
const { setAccountState } = useAccountStatusContext(); | ||
|
||
const t = useTranslations('Account.Wishlist'); | ||
|
||
const handleInputValidation = (e: ChangeEvent<HTMLInputElement>) => { | ||
const validationStatus = e.target.validity.valueMissing; | ||
|
||
setInputValidation(!validationStatus); | ||
}; | ||
|
||
const onSubmit = async (formData: FormData) => { | ||
const submit = await createWishlist(formData); | ||
|
||
if (submit.status === 'success') { | ||
onWishlistCreated(submit.data); | ||
setAccountState({ | ||
status: submit.status, | ||
message: t('messages.created', { name: submit.data.name }), | ||
}); | ||
} | ||
|
||
if (submit.status === 'error') { | ||
setAccountState({ status: submit.status, message: submit.message }); | ||
} | ||
}; | ||
|
||
return ( | ||
<Form action={onSubmit} className="w-full" onSubmit={(e) => e.stopPropagation()}> | ||
<Field className="relative space-y-2 pb-7" name="name"> | ||
<FieldLabel htmlFor="wishlist-name">{t('inputLabel')}</FieldLabel> | ||
<FieldControl asChild> | ||
<Input | ||
// eslint-disable-next-line jsx-a11y/no-autofocus | ||
autoFocus | ||
error={!isInputValid} | ||
id="wishlist-name" | ||
onChange={handleInputValidation} | ||
onInvalid={handleInputValidation} | ||
required | ||
type="text" | ||
/> | ||
</FieldControl> | ||
<FieldMessage | ||
className="absolute inset-x-0 bottom-0 inline-flex w-full text-xs font-normal text-error" | ||
match="valueMissing" | ||
> | ||
{t('emptyName')} | ||
</FieldMessage> | ||
</Field> | ||
<div className="mt-3 flex flex-col lg:flex-row"> | ||
<FormSubmit asChild> | ||
<SubmitButton /> | ||
</FormSubmit> | ||
<DialogPrimitive.Cancel asChild> | ||
<Button className="mt-2 w-full border-0 lg:ms-2 lg:mt-0 lg:w-fit" variant="secondary"> | ||
{t('cancel')} | ||
</Button> | ||
</DialogPrimitive.Cancel> | ||
</div> | ||
</Form> | ||
); | ||
}; |
Oops, something went wrong.