From 788ddc0f43696df607f07133af15a04b29d5447d Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Sun, 2 Apr 2023 19:04:32 +0200 Subject: [PATCH] fix(medusa, admin-ui, medusa-react): Gift Card update fixes and admin UI cleanup (#3676) * fix gc domain issues * add changeset * update changeset * more minor fixes, remove breadcrumb * more cleanup * address feedback --- .changeset/cuddly-trees-cry.md | 7 + .../atoms/date-picker/date-picker.tsx | 1 + .../atoms/date-picker/time-picker.tsx | 1 + .../atoms/number-scroller/index.tsx | 6 +- .../ui/src/components/atoms/spacer/index.tsx | 9 + .../gift-card-balance-form/index.tsx | 67 +++++ .../gift-card-ends-at-form/index.tsx | 57 +++++ .../gift-card-receiver-form/index.tsx | 43 ++++ .../gift-card/gift-card-region-form/index.tsx | 78 ++++++ .../molecules/banner-card/index.tsx | 17 +- .../components/molecules/breadcrumb/index.tsx | 42 ---- .../ui/src/components/organisms/body-card.tsx | 6 +- .../components/organisms/delete-prompt.tsx | 12 +- .../organisms/gift-card-banner/index.tsx | 3 +- .../organisms/invite-modal/index.tsx | 9 +- .../components/organisms/raw-json/index.tsx | 2 +- .../templates/settings-overview.tsx | 2 + .../components/templates/two-split-pane.tsx | 2 +- .../src/domain/collections/details/index.tsx | 2 +- .../ui/src/domain/customers/details/index.tsx | 2 +- .../ui/src/domain/customers/index.tsx | 18 +- .../discounts/details/conditions/index.tsx | 96 +++---- .../ui/src/domain/discounts/details/index.tsx | 14 +- .../ui/src/domain/discounts/index.tsx | 2 + .../src/domain/gift-cards/custom-giftcard.tsx | 237 ++++++++---------- .../details/edit-gift-card-modal.tsx | 176 +++++++------ .../src/domain/gift-cards/details/index.tsx | 205 ++++++++------- .../details/update-balance-modal.tsx | 155 ++++++------ .../ui/src/domain/gift-cards/overview.tsx | 103 ++++---- .../src/domain/inventory/inventory/index.tsx | 2 + .../ui/src/domain/orders/details/index.tsx | 10 +- .../domain/orders/draft-orders/details.tsx | 10 +- .../src/domain/orders/draft-orders/index.tsx | 2 + .../admin-ui/ui/src/domain/orders/index.tsx | 19 +- .../ui/src/domain/pricing/details/index.tsx | 26 +- .../admin-ui/ui/src/domain/pricing/index.tsx | 2 + .../domain/product-categories/pages/index.tsx | 2 + .../ui/src/domain/products/new/index.tsx | 41 +-- .../ui/src/domain/products/overview/index.tsx | 5 +- .../publishable-api-keys/pages/index.tsx | 26 +- .../domain/sales-channels/pages/details.tsx | 52 ++-- .../ui/src/domain/settings/details.tsx | 68 ++--- .../ui/src/domain/settings/regions/index.tsx | 2 +- .../domain/settings/return-reasons/detail.tsx | 2 +- .../domain/settings/return-reasons/index.tsx | 11 +- .../ui/src/domain/settings/taxes/index.tsx | 10 +- .../ui/src/domain/settings/users/index.tsx | 25 +- .../admin-ui/ui/src/utils/form-validator.ts | 4 + .../src/hooks/admin/gift-cards/mutations.ts | 5 +- .../admin/gift-cards/update-gift-card.ts | 6 +- packages/medusa/src/types/gift-card.ts | 2 +- 51 files changed, 997 insertions(+), 709 deletions(-) create mode 100644 .changeset/cuddly-trees-cry.md create mode 100644 packages/admin-ui/ui/src/components/atoms/spacer/index.tsx create mode 100644 packages/admin-ui/ui/src/components/forms/gift-card/gift-card-balance-form/index.tsx create mode 100644 packages/admin-ui/ui/src/components/forms/gift-card/gift-card-ends-at-form/index.tsx create mode 100644 packages/admin-ui/ui/src/components/forms/gift-card/gift-card-receiver-form/index.tsx create mode 100644 packages/admin-ui/ui/src/components/forms/gift-card/gift-card-region-form/index.tsx delete mode 100644 packages/admin-ui/ui/src/components/molecules/breadcrumb/index.tsx diff --git a/.changeset/cuddly-trees-cry.md b/.changeset/cuddly-trees-cry.md new file mode 100644 index 0000000000..437c360db9 --- /dev/null +++ b/.changeset/cuddly-trees-cry.md @@ -0,0 +1,7 @@ +--- +"medusa-react": patch +"@medusajs/admin-ui": patch +"@medusajs/medusa": patch +--- + +fix(admin-ui, medusa-react, medusa): Minor fixes to GC domain in admin UI. Also fixes GC update payload type in medusa-react and medusa. diff --git a/packages/admin-ui/ui/src/components/atoms/date-picker/date-picker.tsx b/packages/admin-ui/ui/src/components/atoms/date-picker/date-picker.tsx index d6f35a881a..48ac612b57 100644 --- a/packages/admin-ui/ui/src/components/atoms/date-picker/date-picker.tsx +++ b/packages/admin-ui/ui/src/components/atoms/date-picker/date-picker.tsx @@ -60,6 +60,7 @@ const DatePicker: React.FC = ({ "shadow-input border-violet-60": isOpen, "border-grey-20": !isOpen, })} + type="button" >
diff --git a/packages/admin-ui/ui/src/components/atoms/date-picker/time-picker.tsx b/packages/admin-ui/ui/src/components/atoms/date-picker/time-picker.tsx index 07aaa17930..b4cb2de328 100644 --- a/packages/admin-ui/ui/src/components/atoms/date-picker/time-picker.tsx +++ b/packages/admin-ui/ui/src/components/atoms/date-picker/time-picker.tsx @@ -53,6 +53,7 @@ const TimePicker: React.FC = ({ "shadow-input border-violet-60": isOpen, "border-grey-20": !isOpen, })} + type="button" >
diff --git a/packages/admin-ui/ui/src/components/atoms/number-scroller/index.tsx b/packages/admin-ui/ui/src/components/atoms/number-scroller/index.tsx index 952fde54da..a07c9a6242 100644 --- a/packages/admin-ui/ui/src/components/atoms/number-scroller/index.tsx +++ b/packages/admin-ui/ui/src/components/atoms/number-scroller/index.tsx @@ -34,7 +34,11 @@ const NumberScroller: React.FC = ({ } )} > -
diff --git a/packages/admin-ui/ui/src/components/atoms/spacer/index.tsx b/packages/admin-ui/ui/src/components/atoms/spacer/index.tsx new file mode 100644 index 0000000000..ee5e958edb --- /dev/null +++ b/packages/admin-ui/ui/src/components/atoms/spacer/index.tsx @@ -0,0 +1,9 @@ +/** + * Spacer that ensures a consistent bottom margin on all pages + * Temporary fix to BodyCard and main layout not having a consistent bottom margin + */ +const Spacer = () => { + return
+} + +export default Spacer diff --git a/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-balance-form/index.tsx b/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-balance-form/index.tsx new file mode 100644 index 0000000000..964936ec2d --- /dev/null +++ b/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-balance-form/index.tsx @@ -0,0 +1,67 @@ +import { Controller } from "react-hook-form" +import FormValidator from "../../../../utils/form-validator" +import { NestedForm } from "../../../../utils/nested-form" +import { formatAmountWithSymbol } from "../../../../utils/prices" +import PriceFormInput from "../../general/prices-form/price-form-input" + +export type GiftCardBalanceFormType = { + amount: number +} + +export type GiftCardBalanceFormProps = { + form: NestedForm + currencyCode: string + originalAmount?: number +} + +const GiftCardBalanceForm = ({ + form, + currencyCode, + originalAmount, +}: GiftCardBalanceFormProps) => { + const { + control, + path, + formState: { errors }, + } = form + + return ( + { + return ( + + ) + }} + /> + ) +} + +export default GiftCardBalanceForm diff --git a/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-ends-at-form/index.tsx b/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-ends-at-form/index.tsx new file mode 100644 index 0000000000..941ec7565a --- /dev/null +++ b/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-ends-at-form/index.tsx @@ -0,0 +1,57 @@ +import { Controller } from "react-hook-form" +import { NestedForm } from "../../../../utils/nested-form" +import DatePicker from "../../../atoms/date-picker/date-picker" +import TimePicker from "../../../atoms/date-picker/time-picker" +import SwitchableItem from "../../../molecules/switchable-item" + +export type GiftCardEndsAtFormType = { + ends_at: Date | null +} + +type GiftCardEndsAtFormProps = { + form: NestedForm +} + +const GiftCardEndsAtForm = ({ form }: GiftCardEndsAtFormProps) => { + const { control, path } = form + + return ( + { + return ( + { + if (value) { + onChange(null) + } else { + onChange( + new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000) + ) + } + }} + title="Gift Card has an expiry date?" + description="Schedule the Gift Card to deactivate in the future." + > +
+ + +
+
+ ) + }} + /> + ) +} + +export default GiftCardEndsAtForm diff --git a/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-receiver-form/index.tsx b/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-receiver-form/index.tsx new file mode 100644 index 0000000000..0516184d7a --- /dev/null +++ b/packages/admin-ui/ui/src/components/forms/gift-card/gift-card-receiver-form/index.tsx @@ -0,0 +1,43 @@ +import FormValidator from "../../../../utils/form-validator" +import { NestedForm } from "../../../../utils/nested-form" +import InputField from "../../../molecules/input" +import TextArea from "../../../molecules/textarea" + +export type GiftCardReceiverFormType = { + email: string + message?: string +} + +type GiftCardReceiverFormProps = { + form: NestedForm +} + +const GiftCardReceiverForm = ({ form }: GiftCardReceiverFormProps) => { + const { + register, + path, + formState: { errors }, + } = form + + return ( +
+ +