From 6e613f4f50f8c4e662baaa6ab633bdf16db4a09a Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:14:19 +0200 Subject: [PATCH] feat: Update toast design (#8018) **What** - Updates the Toast component and `toast` util to match the latest design. - Updates every usage of `toast` as `dismissableLabel` is no longer a valid prop, as we now render a X mark instead of a text button. --- .../dashboard/src/i18n/translations/en.json | 17 +- .../api-key-create-form.tsx | 20 +-- .../api-key-general-section.tsx | 28 ++-- .../api-key-sales-channel-section.tsx | 33 ++-- .../edit-api-key-form/edit-api-key-form.tsx | 19 +-- .../api-key-row-actions.tsx | 33 ++-- .../api-key-sales-channels-form.tsx | 14 +- .../add-campaign-promotions-form.tsx | 15 +- .../edit-campaign-budget-form.tsx | 14 +- .../create-campaign-form.tsx | 14 +- .../campaign-general-section.tsx | 14 +- .../edit-campaign-form/edit-campaign-form.tsx | 14 +- .../components/campaign-list-table.tsx | 20 +-- .../create-category-form.tsx | 17 +- .../category-product-section.tsx | 16 +- .../category-edit/category-edit.tsx | 9 +- .../edit-category-form/edit-category-form.tsx | 30 +++- .../organize-category-form.tsx | 7 +- .../edit-category-products-form.tsx | 16 +- .../use-delete-product-category-action.tsx | 12 +- .../add-products-to-collection-form.tsx | 12 +- .../collection-product-section.tsx | 26 ++-- .../add-customers-form/add-customers-form.tsx | 12 +- .../create-customer-group-form.tsx | 14 +- .../customer-group-general-section.tsx | 17 +- .../edit-customer-group-form.tsx | 17 +- .../customer-group-list-table.tsx | 18 +-- .../create-customer-form.tsx | 16 +- .../customer-general-section.tsx | 17 +- .../customer-group-section.tsx | 25 ++- .../edit-customer-form/edit-customer-form.tsx | 14 +- .../add-customer-groups-form.tsx | 5 +- .../create-inventory-item-form.tsx | 16 +- .../components/adjust-inventory-form.tsx | 34 ++-- .../components/edit-item-attributes-form.tsx | 17 +- .../components/edit-item-form.tsx | 16 +- .../components/manage-locations-form.tsx | 36 ++--- .../reservation-actions.tsx | 12 +- .../dashboard/src/routes/invite/invite.tsx | 23 ++- .../create-location-form.tsx | 12 +- .../location-general-section.tsx | 70 +++------ .../edit-location-form/edit-location-form.tsx | 16 +- .../location-list-item/location-list-item.tsx | 14 +- .../edit-sales-channels-form.tsx | 12 +- .../create-service-zone-form.tsx | 18 +-- .../edit-service-zone-form.tsx | 19 +-- .../edit-service-zone-areas-form.tsx | 21 +-- .../create-shipping-options-form.tsx | 16 +- .../edit-shipping-option-form.tsx | 21 +-- .../edit-shipping-options-pricing-form.tsx | 9 +- .../order-create-fulfillment-form.tsx | 11 +- .../order-create-shipment-form.tsx | 35 ++--- .../order-fulfillment-section.tsx | 30 ++-- .../hooks/use-delete-price-list-action.tsx | 16 +- .../hooks/use-delete-product-type-action.tsx | 12 +- .../create-product-type-form.tsx | 16 +- .../edit-product-type-form.tsx | 21 +-- .../manage-variant-inventory-items-form.tsx | 11 +- .../create-product-option-form.tsx | 19 +-- .../product-create-form.tsx | 134 ++++++++-------- .../product-list-table/product-list-table.tsx | 2 - .../product-organization-form.tsx | 19 +-- .../edit-profile-form/edit-profile-form.tsx | 16 +- .../create-promotion-form.tsx | 19 +-- .../add-countries-form/add-countries-form.tsx | 31 ++-- .../create-region-form/create-region-form.tsx | 9 +- .../region-country-section.tsx | 60 ++++---- .../region-general-section.tsx | 22 ++- .../edit-region-form/edit-region-form.tsx | 8 +- .../components/edit-reservation-form.tsx | 8 +- .../create-reservation-form.tsx | 8 +- .../add-products-to-sales-channel-form.tsx | 15 +- .../create-sales-channel-form.tsx | 11 +- .../sales-channel-general-section.tsx | 24 ++- .../sales-channel-product-section.tsx | 38 ++--- .../edit-sales-channel-form.tsx | 15 +- .../components/sales-channel-list-table.tsx | 22 ++- .../create-shipping-profile-form.tsx | 14 +- .../shipping-profile-general-section.tsx | 14 +- .../shipping-options-row-actions.tsx | 14 +- .../add-currencies-form.tsx | 27 ++-- .../store-currency-section.tsx | 54 +++---- .../edit-store-form/edit-store-form.tsx | 43 ++---- packages/design-system/ui/package.json | 2 +- .../ui/src/components/toast/toast.stories.tsx | 16 ++ .../ui/src/components/toast/toast.tsx | 145 +++++++++--------- packages/design-system/ui/src/utils/toast.tsx | 85 +++++----- yarn.lock | 10 +- 88 files changed, 811 insertions(+), 1182 deletions(-) diff --git a/packages/admin-next/dashboard/src/i18n/translations/en.json b/packages/admin-next/dashboard/src/i18n/translations/en.json index 46366a2504..2ebbfd6585 100644 --- a/packages/admin-next/dashboard/src/i18n/translations/en.json +++ b/packages/admin-next/dashboard/src/i18n/translations/en.json @@ -456,6 +456,14 @@ "products": { "list": { "noRecordsMessage": "There are no products in the collection." + }, + "add": { + "successToast_one": "Product was successfully added to the collection.", + "successToast_other": "Products were successfully added to the collection." + }, + "remove": { + "successToast_one": "Product was successfully removed from the collection.", + "successToast_other": "Products were successfully removed from the collection." } } }, @@ -471,6 +479,11 @@ }, "successToast": "Category {{name}} was successfully created." }, + "edit": { + "header": "Edit Category", + "description": "Edit the category to update its details.", + "successToast": "Category was successfully updated." + }, "delete": { "confirmation": "You are about to delete the category {{name}}. This action cannot be undone.", "successToast": "Category {{name}} was successfully deleted." @@ -556,7 +569,9 @@ "deleteSuccessToast": "Reservation was successfully deleted." }, "toast": { - "updateLocations": "Locations updated successfully." + "updateLocations": "Locations updated successfully.", + "updateLevel": "Inventory level updated successfully.", + "updateItem": "Inventory item updated successfully." } }, "giftCards": { diff --git a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-create/components/api-key-create-form/api-key-create-form.tsx b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-create/components/api-key-create-form/api-key-create-form.tsx index c0aeba9a51..7de281ece1 100644 --- a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-create/components/api-key-create-form/api-key-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-create/components/api-key-create-form/api-key-create-form.tsx @@ -59,10 +59,7 @@ export const ApiKeyCreateForm = ({ keyType }: ApiKeyCreateFormProps) => { { title: values.title, type: keyType }, { onSuccess: ({ api_key }) => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.create.successToast"), - dismissLabel: t("general.close"), - }) + toast.success(t("apiKeyManagement.create.successToast")) switch (keyType) { case ApiKeyType.PUBLISHABLE: @@ -74,10 +71,7 @@ export const ApiKeyCreateForm = ({ keyType }: ApiKeyCreateFormProps) => { } }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, } ) @@ -85,17 +79,11 @@ export const ApiKeyCreateForm = ({ keyType }: ApiKeyCreateFormProps) => { const handleCopyToken = () => { if (!createdKey) { - toast.error(t("general.error"), { - dismissLabel: t("general.close"), - description: t("apiKeyManagement.create.copySecretTokenFailure"), - }) + toast.error(t("apiKeyManagement.create.copySecretTokenFailure")) } navigator.clipboard.writeText(createdKey?.token ?? "") - toast.success(t("general.success"), { - description: t("apiKeyManagement.create.copySecretTokenSuccess"), - dismissLabel: t("general.close"), - }) + toast.success(t("apiKeyManagement.create.copySecretTokenSuccess")) } const handleGoToSecretKey = () => { diff --git a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-general-section/api-key-general-section.tsx b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-general-section/api-key-general-section.tsx index 112184d8be..287f99782d 100644 --- a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-general-section/api-key-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-general-section/api-key-general-section.tsx @@ -56,19 +56,15 @@ export const ApiKeyGeneralSection = ({ apiKey }: ApiKeyGeneralSectionProps) => { await deleteAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.delete.successToast", { + toast.success( + t("apiKeyManagement.delete.successToast", { title: apiKey.title, - }), - dismissLabel: t("general.close"), - }) + }) + ) navigate("..", { replace: true }) }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) } @@ -89,18 +85,14 @@ export const ApiKeyGeneralSection = ({ apiKey }: ApiKeyGeneralSectionProps) => { await revokeAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.revoke.successToast", { + toast.success( + t("apiKeyManagement.revoke.successToast", { title: apiKey.title, - }), - dismissLabel: t("general.close"), - }) + }) + ) }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-sales-channel-section/api-key-sales-channel-section.tsx b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-sales-channel-section/api-key-sales-channel-section.tsx index ae53b9f5f9..8a900831ea 100644 --- a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-sales-channel-section/api-key-sales-channel-section.tsx +++ b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-detail/components/api-key-sales-channel-section/api-key-sales-channel-section.tsx @@ -82,22 +82,15 @@ export const ApiKeySalesChannelSection = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t( - "apiKeyManagement.removeSalesChannel.successToastBatch", - { - count: keys.length, - } - ), - dismissLabel: t("general.close"), - }) + toast.success( + t("apiKeyManagement.removeSalesChannel.successToastBatch", { + count: keys.length, + }) + ) setRowSelection({}) }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, } ) @@ -180,18 +173,14 @@ const SalesChannelActions = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.removeSalesChannel.successToast", { + toast.success( + t("apiKeyManagement.removeSalesChannel.successToast", { count: 1, - }), - dismissLabel: t("general.close"), - }) + }) + ) }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-edit/components/edit-api-key-form/edit-api-key-form.tsx b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-edit/components/edit-api-key-form/edit-api-key-form.tsx index d60bc0b243..977604cd6a 100644 --- a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-edit/components/edit-api-key-form/edit-api-key-form.tsx +++ b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-edit/components/edit-api-key-form/edit-api-key-form.tsx @@ -6,10 +6,7 @@ import * as zod from "zod" import { ApiKeyDTO } from "@medusajs/types" import { Form } from "../../../../../components/common/form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateApiKey } from "../../../../../hooks/api/api-keys" type EditApiKeyFormProps = { @@ -36,19 +33,15 @@ export const EditApiKeyForm = ({ apiKey }: EditApiKeyFormProps) => { const handleSubmit = form.handleSubmit(async (data) => { await mutateAsync(data, { onSuccess: ({ api_key }) => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.edit.successToast", { + toast.success( + t("apiKeyManagement.edit.successToast", { title: api_key.title, - }), - dismissLabel: t("general.close"), - }) + }) + ) handleSuccess() }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) }) diff --git a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-list/components/api-key-management-list-table/api-key-row-actions.tsx b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-list/components/api-key-management-list-table/api-key-row-actions.tsx index 6b84fceb45..5e59cbfed0 100644 --- a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-list/components/api-key-management-list-table/api-key-row-actions.tsx +++ b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-list/components/api-key-management-list-table/api-key-row-actions.tsx @@ -35,18 +35,14 @@ export const ApiKeyRowActions = ({ await deleteAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.delete.successToast", { + toast.success( + t("apiKeyManagement.delete.successToast", { title: apiKey.title, - }), - dismissLabel: t("general.close"), - }) + }) + ) }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) } @@ -67,28 +63,21 @@ export const ApiKeyRowActions = ({ await revokeAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.revoke.successToast", { + toast.success( + t("apiKeyManagement.revoke.successToast", { title: apiKey.title, - }), - dismissLabel: t("general.close"), - }) + }) + ) }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) } const handleCopyToken = () => { navigator.clipboard.writeText(apiKey.token) - toast.success(t("general.success"), { - description: t("apiKeyManagement.actions.copySuccessToast"), - dismissLabel: t("general.close"), - }) + toast.success(t("apiKeyManagement.actions.copySuccessToast")) } return ( diff --git a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-sales-channels/components/api-key-sales-channels-form/api-key-sales-channels-form.tsx b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-sales-channels/components/api-key-sales-channels-form/api-key-sales-channels-form.tsx index 49a669a46c..4b8f23f0a6 100644 --- a/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-sales-channels/components/api-key-sales-channels-form/api-key-sales-channels-form.tsx +++ b/packages/admin-next/dashboard/src/routes/api-key-management/api-key-management-sales-channels/components/api-key-sales-channels-form/api-key-sales-channels-form.tsx @@ -102,20 +102,16 @@ export const ApiKeySalesChannelsForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("apiKeyManagement.salesChannels.successToast", { + toast.success( + t("apiKeyManagement.salesChannels.successToast", { count: values.sales_channel_ids.length, - }), - dismissLabel: t("general.close"), - }) + }) + ) handleSuccess() }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/campaigns/add-campaign-promotions/components/add-campaign-promotions-form.tsx b/packages/admin-next/dashboard/src/routes/campaigns/add-campaign-promotions/components/add-campaign-promotions-form.tsx index 891eebabfb..4eebace8b0 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/add-campaign-promotions/components/add-campaign-promotions-form.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/add-campaign-promotions/components/add-campaign-promotions-form.tsx @@ -95,19 +95,14 @@ export const AddCampaignPromotionsForm = ({ { add: values.promotion_ids }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("campaigns.promotions.toast.success", { + toast.success( + t("campaigns.promotions.toast.success", { count: values.promotion_ids.length, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, - onError: (error) => - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }), + onError: (error) => toast.error(error.message), } ) }) diff --git a/packages/admin-next/dashboard/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx b/packages/admin-next/dashboard/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx index 6a87ec6251..ae8cf34208 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx @@ -41,20 +41,16 @@ export const EditCampaignBudgetForm = ({ }, { onSuccess: ({ campaign }) => { - toast.success(t("general.success"), { - description: t("campaigns.edit.successToast", { + toast.success( + t("campaigns.edit.successToast", { name: campaign.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx b/packages/admin-next/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx index 44cfa517f5..49c5611a40 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx @@ -62,19 +62,15 @@ export const CreateCampaignForm = () => { }, { onSuccess: ({ campaign }) => { - toast.success(t("general.success"), { - description: t("campaigns.create.successToast", { + toast.success( + t("campaigns.create.successToast", { name: campaign.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/campaigns/${campaign.id}`) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/campaigns/campaign-detail/components/campaign-general-section/campaign-general-section.tsx b/packages/admin-next/dashboard/src/routes/campaigns/campaign-detail/components/campaign-general-section/campaign-general-section.tsx index 4fec7d1a50..49f9629463 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/campaign-detail/components/campaign-general-section/campaign-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/campaign-detail/components/campaign-general-section/campaign-general-section.tsx @@ -48,20 +48,16 @@ export const CampaignGeneralSection = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("campaigns.delete.successToast", { + toast.success( + t("campaigns.delete.successToast", { name: campaign.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) navigate("/campaigns", { replace: true }) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/campaigns/campaign-edit/components/edit-campaign-form/edit-campaign-form.tsx b/packages/admin-next/dashboard/src/routes/campaigns/campaign-edit/components/edit-campaign-form/edit-campaign-form.tsx index 3682be1744..202301f046 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/campaign-edit/components/edit-campaign-form/edit-campaign-form.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/campaign-edit/components/edit-campaign-form/edit-campaign-form.tsx @@ -48,20 +48,16 @@ export const EditCampaignForm = ({ campaign }: EditCampaignFormProps) => { }, { onSuccess: ({ campaign }) => { - toast.success(t("general.success"), { - description: t("campaigns.edit.successToast", { + toast.success( + t("campaigns.edit.successToast", { name: campaign.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/campaigns/campaign-list/components/campaign-list-table.tsx b/packages/admin-next/dashboard/src/routes/campaigns/campaign-list/components/campaign-list-table.tsx index aa37a71e20..76e8036f27 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/campaign-list/components/campaign-list-table.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/campaign-list/components/campaign-list-table.tsx @@ -95,18 +95,14 @@ const CampaignActions = ({ campaign }: { campaign: CampaignResponse }) => { return } - try { - await mutateAsync() - toast.success(t("general.success"), { - description: t("campaigns.toast.delete"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + await mutateAsync(undefined, { + onSuccess: () => { + toast.success(t("campaigns.toast.delete")) + }, + onError: (e) => { + toast.error(e.message) + }, + }) } return ( diff --git a/packages/admin-next/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx b/packages/admin-next/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx index 0f7d6e47a2..cf358eeb55 100644 --- a/packages/admin-next/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx @@ -92,23 +92,16 @@ export const CreateCategoryForm = ({ }, { onSuccess: ({ product_category }) => { - toast.success(t("general.success"), { - description: t("categories.create.successToast", { + toast.success( + t("categories.create.successToast", { name: product_category.name, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/categories/${product_category.id}`) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) - + toast.error(error.message) setShouldFreeze(false) }, } diff --git a/packages/admin-next/dashboard/src/routes/categories/category-detail/components/category-product-section/category-product-section.tsx b/packages/admin-next/dashboard/src/routes/categories/category-detail/components/category-product-section/category-product-section.tsx index bfe6906386..bff3aa4289 100644 --- a/packages/admin-next/dashboard/src/routes/categories/category-detail/components/category-product-section/category-product-section.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/category-detail/components/category-product-section/category-product-section.tsx @@ -88,22 +88,16 @@ export const CategoryProductSection = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("categories.products.remove.successToast", { + toast.success( + t("categories.products.remove.successToast", { count: selected.length, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) setSelection({}) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/categories/category-edit/category-edit.tsx b/packages/admin-next/dashboard/src/routes/categories/category-edit/category-edit.tsx index 51fa819638..07115e6714 100644 --- a/packages/admin-next/dashboard/src/routes/categories/category-edit/category-edit.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/category-edit/category-edit.tsx @@ -1,5 +1,6 @@ import { Heading } from "@medusajs/ui" +import { useTranslation } from "react-i18next" import { useParams } from "react-router-dom" import { RouteDrawer } from "../../../components/modals" import { useProductCategory } from "../../../hooks/api/categories" @@ -7,6 +8,7 @@ import { EditCategoryForm } from "./components/edit-category-form" export const CategoryEdit = () => { const { id } = useParams() + const { t } = useTranslation() const { product_category, isPending, isError, error } = useProductCategory( id! @@ -21,7 +23,12 @@ export const CategoryEdit = () => { return ( - Edit + + {t("categories.edit.header")} + + + {t("categories.edit.description")} + {ready && } diff --git a/packages/admin-next/dashboard/src/routes/categories/category-edit/components/edit-category-form/edit-category-form.tsx b/packages/admin-next/dashboard/src/routes/categories/category-edit/components/edit-category-form/edit-category-form.tsx index 4edb2a6ede..d9fb26104e 100644 --- a/packages/admin-next/dashboard/src/routes/categories/category-edit/components/edit-category-form/edit-category-form.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/category-edit/components/edit-category-form/edit-category-form.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { Button, Input, Select, Textarea } from "@medusajs/ui" +import { Button, Input, Select, Textarea, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" @@ -7,7 +7,8 @@ import { z } from "zod" import { HttpTypes } from "@medusajs/types" import { Form } from "../../../../../components/common/form" import { HandleInput } from "../../../../../components/inputs/handle-input" -import { RouteDrawer } from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" +import { useUpdateProductCategory } from "../../../../../hooks/api/categories" const EditCategorySchema = z.object({ name: z.string().min(1), @@ -23,6 +24,7 @@ type EditCategoryFormProps = { export const EditCategoryForm = ({ category }: EditCategoryFormProps) => { const { t } = useTranslation() + const { handleSuccess } = useRouteModal() const form = useForm>({ defaultValues: { @@ -35,9 +37,27 @@ export const EditCategoryForm = ({ category }: EditCategoryFormProps) => { resolver: zodResolver(EditCategorySchema), }) - const isPending = false - - const handleSubmit = form.handleSubmit(async (data) => console.log(data)) + const { mutateAsync, isPending } = useUpdateProductCategory(category.id) + const handleSubmit = form.handleSubmit(async (data) => { + await mutateAsync( + { + name: data.name, + description: data.description, + handle: data.handle, + is_active: data.status === "active", + is_internal: data.visibility === "internal", + }, + { + onSuccess: () => { + toast.success(t("categories.edit.successToast")) + handleSuccess() + }, + onError: (error) => { + toast.error(error.message) + }, + } + ) + }) return ( diff --git a/packages/admin-next/dashboard/src/routes/categories/category-organize/components/organize-category-form/organize-category-form.tsx b/packages/admin-next/dashboard/src/routes/categories/category-organize/components/organize-category-form/organize-category-form.tsx index 71e7504924..3c739bf1b7 100644 --- a/packages/admin-next/dashboard/src/routes/categories/category-organize/components/organize-category-form/organize-category-form.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/category-organize/components/organize-category-form/organize-category-form.tsx @@ -4,7 +4,6 @@ import { Spinner } from "@medusajs/icons" import { FetchError } from "@medusajs/js-sdk" import { HttpTypes } from "@medusajs/types" import { toast } from "@medusajs/ui" -import { t } from "i18next" import { RouteFocusModal } from "../../../../../components/modals" import { categoriesQueryKeys, @@ -71,11 +70,7 @@ export const OrganizeCategoryForm = () => { context?.previousValue ) - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("general.close"), - dismissable: true, - }) + toast.error(error.message) }, onSettled: async (_data, _error, variables) => { await queryClient.invalidateQueries({ diff --git a/packages/admin-next/dashboard/src/routes/categories/category-products/components/edit-category-products-form/edit-category-products-form.tsx b/packages/admin-next/dashboard/src/routes/categories/category-products/components/edit-category-products-form/edit-category-products-form.tsx index 93f7312f81..68fba426ad 100644 --- a/packages/admin-next/dashboard/src/routes/categories/category-products/components/edit-category-products-form/edit-category-products-form.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/category-products/components/edit-category-products-form/edit-category-products-form.tsx @@ -116,22 +116,16 @@ export const EditCategoryProductsForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("categories.products.add.disabledTooltip", { + toast.success( + t("categories.products.add.disabledTooltip", { count: data.product_ids.length, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/categories/common/hooks/use-delete-product-category-action.tsx b/packages/admin-next/dashboard/src/routes/categories/common/hooks/use-delete-product-category-action.tsx index 5265036315..1ce74ed3a1 100644 --- a/packages/admin-next/dashboard/src/routes/categories/common/hooks/use-delete-product-category-action.tsx +++ b/packages/admin-next/dashboard/src/routes/categories/common/hooks/use-delete-product-category-action.tsx @@ -29,20 +29,18 @@ export const useDeleteProductCategoryAction = ( await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("categories.delete.successToast", { + toast.success( + t("categories.delete.successToast", { name: category.name, - }), - }) + }) + ) navigate("/categories", { replace: true, }) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - }) + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/collections/collection-add-products/components/add-products-to-collection-form/add-products-to-collection-form.tsx b/packages/admin-next/dashboard/src/routes/collections/collection-add-products/components/add-products-to-collection-form/add-products-to-collection-form.tsx index fbeb6745fc..abb0039b0f 100644 --- a/packages/admin-next/dashboard/src/routes/collections/collection-add-products/components/add-products-to-collection-form/add-products-to-collection-form.tsx +++ b/packages/admin-next/dashboard/src/routes/collections/collection-add-products/components/add-products-to-collection-form/add-products-to-collection-form.tsx @@ -103,7 +103,7 @@ export const AddProductsToCollectionForm = ({ const filters = useProductTableFilters(["collections"]) const { table } = useDataTable({ - data: (products ?? []) as ExtendedProductDTO[], + data: products ?? [], columns, count, pageSize: PAGE_SIZE, @@ -127,13 +127,15 @@ export const AddProductsToCollectionForm = ({ }, { onSuccess: () => { + toast.success( + t("collections.products.add.successToast", { + count: values.add.length, + }) + ) handleSuccess() }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/collections/collection-detail/components/collection-product-section/collection-product-section.tsx b/packages/admin-next/dashboard/src/routes/collections/collection-detail/components/collection-product-section/collection-product-section.tsx index bd0b926347..a2674c7fc9 100644 --- a/packages/admin-next/dashboard/src/routes/collections/collection-detail/components/collection-product-section/collection-product-section.tsx +++ b/packages/admin-next/dashboard/src/routes/collections/collection-detail/components/collection-product-section/collection-product-section.tsx @@ -30,7 +30,7 @@ export const CollectionProductSection = ({ { limit: PAGE_SIZE, ...searchParams, - collection_id: [collection.id], + collection_id: [collection.id!], }, { placeholderData: keepPreviousData, @@ -78,11 +78,15 @@ export const CollectionProductSection = ({ remove: ids, }, { + onSuccess: () => { + toast.success( + t("collections.products.remove.successToast", { + count: ids.length, + }) + ) + }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) @@ -167,11 +171,15 @@ const ProductActions = ({ remove: [product.id], }, { + onSuccess: () => { + toast.success( + t("collections.products.remove.successToast", { + count: 1, + }) + ) + }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx index 1858796c5f..51efe99733 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx @@ -109,15 +109,17 @@ export const AddCustomersForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("customerGroups.customers.add.successToast", { + toast.success( + t("customerGroups.customers.add.successToast", { count: data.customer_ids.length, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/customer-groups/${customerGroupId}`) }, + onError: (error) => { + toast.error(error.message) + }, } ) }) diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-create/components/create-customer-group-form/create-customer-group-form.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-create/components/create-customer-group-form/create-customer-group-form.tsx index 8db2aced8e..a43d84dd08 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-create/components/create-customer-group-form/create-customer-group-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-create/components/create-customer-group-form/create-customer-group-form.tsx @@ -35,20 +35,16 @@ export const CreateCustomerGroupForm = () => { }, { onSuccess: ({ customer_group }) => { - toast.success(t("general.success"), { - description: t("customerGroups.create.successToast", { + toast.success( + t("customerGroups.create.successToast", { name: customer_group.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/customer-groups/${customer_group.id}`) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-general-section/customer-group-general-section.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-general-section/customer-group-general-section.tsx index 4a5a42f349..78d3ec93fa 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-general-section/customer-group-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-general-section/customer-group-general-section.tsx @@ -1,10 +1,11 @@ import { PencilSquare, Trash } from "@medusajs/icons" +import { HttpTypes } from "@medusajs/types" import { Container, Heading, Text, toast, usePrompt } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" + import { ActionMenu } from "../../../../../components/common/action-menu" import { useDeleteCustomerGroup } from "../../../../../hooks/api/customer-groups" -import { HttpTypes } from "@medusajs/types" type CustomerGroupGeneralSectionProps = { group: HttpTypes.AdminCustomerGroup @@ -35,20 +36,16 @@ export const CustomerGroupGeneralSection = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("customerGroups.delete.successToast", { + toast.success( + t("customerGroups.delete.successToast", { name: group.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) navigate("/customer-groups", { replace: true }) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-edit/components/edit-customer-group-form/edit-customer-group-form.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-edit/components/edit-customer-group-form/edit-customer-group-form.tsx index f063344393..5d47aae20c 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-edit/components/edit-customer-group-form/edit-customer-group-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-edit/components/edit-customer-group-form/edit-customer-group-form.tsx @@ -5,10 +5,7 @@ import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import * as z from "zod" import { Form } from "../../../../../components/common/form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateCustomerGroup } from "../../../../../hooks/api/customer-groups" type EditCustomerGroupFormProps = { @@ -37,15 +34,17 @@ export const EditCustomerGroupForm = ({ const handleSubmit = form.handleSubmit(async (data) => { await mutateAsync(data, { onSuccess: ({ customer_group }) => { - toast.success(t("general.success"), { - description: t("customerGroups.edit.successToast", { + toast.success( + t("customerGroups.edit.successToast", { name: customer_group.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, + onError: (error) => { + toast.error(error.message) + }, }) }) diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-list/components/customer-group-list-table/customer-group-list-table.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-list/components/customer-group-list-table/customer-group-list-table.tsx index 009aa359a6..65f4cf5082 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-list/components/customer-group-list-table/customer-group-list-table.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-list/components/customer-group-list-table/customer-group-list-table.tsx @@ -3,15 +3,16 @@ import { Button, Container, Heading, + Text, toast, usePrompt, - Text, } from "@medusajs/ui" import { createColumnHelper } from "@tanstack/react-table" import { useMemo } from "react" import { useTranslation } from "react-i18next" import { Link } from "react-router-dom" +import { HttpTypes } from "@medusajs/types" import { ActionMenu } from "../../../../../components/common/action-menu" import { DataTable } from "../../../../../components/table/data-table" import { @@ -22,7 +23,6 @@ import { useCustomerGroupTableColumns } from "../../../../../hooks/table/columns import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters" import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query" import { useDataTable } from "../../../../../hooks/use-data-table" -import { HttpTypes } from "@medusajs/types" const PAGE_SIZE = 20 @@ -112,18 +112,14 @@ const CustomerGroupRowActions = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("customerGroups.delete.successToast", { + toast.success( + t("customerGroups.delete.successToast", { name: group.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-create/components/create-customer-form/create-customer-form.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-create/components/create-customer-form/create-customer-form.tsx index cb7ea9de2a..c786a3c0b3 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-create/components/create-customer-form/create-customer-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-create/components/create-customer-form/create-customer-form.tsx @@ -39,7 +39,7 @@ export const CreateCustomerForm = () => { const handleSubmit = form.handleSubmit(async (data) => { await mutateAsync( { - email: data.email || undefined, + email: data.email, first_name: data.first_name || undefined, last_name: data.last_name || undefined, company_name: data.company_name || undefined, @@ -47,19 +47,15 @@ export const CreateCustomerForm = () => { }, { onSuccess: ({ customer }) => { - toast.success(t("general.success"), { - description: t("customers.create.successToast", { + toast.success( + t("customers.create.successToast", { email: customer.email, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/customers/${customer.id}`) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-general-section/customer-general-section.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-general-section/customer-general-section.tsx index 5b1058e0be..559622629c 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-general-section/customer-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-general-section/customer-general-section.tsx @@ -1,4 +1,5 @@ import { PencilSquare, Trash } from "@medusajs/icons" +import { HttpTypes } from "@medusajs/types" import { Container, Heading, @@ -9,9 +10,9 @@ import { } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" + import { ActionMenu } from "../../../../../components/common/action-menu" import { useDeleteCustomer } from "../../../../../hooks/api/customers" -import { HttpTypes } from "@medusajs/types" type CustomerGeneralSectionProps = { customer: HttpTypes.AdminCustomer @@ -53,20 +54,16 @@ export const CustomerGeneralSection = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("customers.delete.successToast", { + toast.success( + t("customers.delete.successToast", { email: customer.email, - }), - dismissLabel: t("actions.close"), - }) + }) + ) navigate("/customers", { replace: true }) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx index 02c4b86f0e..16f0e7e0e7 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx @@ -81,7 +81,7 @@ export const CustomerGroupSection = ({ title: t("general.areYouSure"), description: t("customers.groups.removeMany", { groups: customer_groups - .filter((g) => customerGroupIds.includes(g.id)) + ?.filter((g) => customerGroupIds.includes(g.id)) .map((g) => g.name) .join(","), }), @@ -109,10 +109,7 @@ export const CustomerGroupSection = ({ queryKey: customerGroupsQueryKeys.lists(), }) } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("general.close"), - }) + toast.error(e.message) } } @@ -150,7 +147,7 @@ export const CustomerGroupSection = ({ ]} queryObject={raw} noRecords={{ - message: t("customers.groups.list.noRecordsMessage") + message: t("customers.groups.list.noRecordsMessage"), }} /> @@ -183,14 +180,14 @@ const CustomerGroupRowActions = ({ return } - try { - await mutateAsync({ customer_ids: [customerId] }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("general.close"), - }) - } + await mutateAsync( + { customer_ids: [customerId] }, + { + onError: (error) => { + toast.error(error.message) + }, + } + ) } return ( diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-edit/components/edit-customer-form/edit-customer-form.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-edit/components/edit-customer-form/edit-customer-form.tsx index 3ea9c7e97d..bf4fe3ebc3 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-edit/components/edit-customer-form/edit-customer-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-edit/components/edit-customer-form/edit-customer-form.tsx @@ -61,20 +61,16 @@ export const EditCustomerForm = ({ customer }: EditCustomerFormProps) => { }, { onSuccess: ({ customer }) => { - toast.success(t("general.success"), { - description: t("customers.edit.successToast", { + toast.success( + t("customers.edit.successToast", { email: customer.email, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx b/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx index cc29c9328a..ba217b4b3b 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx @@ -130,10 +130,7 @@ export const AddCustomerGroupsForm = ({ handleSuccess(`/customers/${customerId}`) } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) } finally { setIsPending(false) } diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-create/components/create-inventory-item-form/create-inventory-item-form.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-create/components/create-inventory-item-form/create-inventory-item-form.tsx index f159a1ce7d..398e4fe165 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-create/components/create-inventory-item-form/create-inventory-item-form.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-create/components/create-inventory-item-form/create-inventory-item-form.tsx @@ -89,7 +89,7 @@ export function CreateInventoryItemForm({}: CreateInventoryItemFormProps) { useCreateInventoryItem() const handleSubmit = form.handleSubmit(async (data) => { - let { locations, ...payload } = data + const { locations, ...payload } = data for (const k in payload) { if (payload[k] === "") { @@ -119,18 +119,12 @@ export function CreateInventoryItemForm({}: CreateInventoryItemFormProps) { queryKey: inventoryItemsQueryKeys.lists(), }) } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) } handleSuccess() } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) } }) @@ -344,7 +338,7 @@ export function CreateInventoryItemForm({}: CreateInventoryItemFormProps) { /> - {/**/} {/* )*/} {/* }}*/} - {/*/>*/} + {/* />*/} diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx index 53905d578e..aeca5214b1 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/adjust-inventory/components/adjust-inventory-form.tsx @@ -3,10 +3,7 @@ import * as zod from "zod" import { HttpTypes, InventoryLevelDTO, StockLocationDTO } from "@medusajs/types" import { Button, Input, Text, toast } from "@medusajs/ui" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../../components/modals" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" @@ -69,23 +66,20 @@ export const AdjustInventoryForm = ({ return handleSuccess() } - try { - await mutateAsync({ + await mutateAsync( + { stocked_quantity: value.stocked_quantity, - }) - - toast.success(t("general.success"), { - description: t("inventory.toast.updateLevel"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } - - return handleSuccess() + }, + { + onSuccess: () => { + toast.success(t("inventory.toast.updateLevel")) + handleSuccess() + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) }) return ( diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx index 52e940d948..ac2e652529 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx @@ -1,16 +1,14 @@ import * as zod from "zod" import { Button, Input, toast } from "@medusajs/ui" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../../components/modals" import { zodResolver } from "@hookform/resolvers/zod" import { InventoryTypes } from "@medusajs/types" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" + import { Form } from "../../../../../../components/common/form" import { CountrySelect } from "../../../../../../components/inputs/country-select" import { useUpdateInventoryItem } from "../../../../../../hooks/api/inventory" @@ -57,17 +55,10 @@ export const EditInventoryItemAttributesForm = ({ const handleSubmit = form.handleSubmit(async (values) => { await mutateAsync(values, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("inventory.toast.update"), - dismissLabel: t("actions.close"), - }) + toast.success(t("inventory.toast.updateItem")) handleSuccess() }, - onError: (error) => - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }), + onError: (error) => toast.error(error.message), }) }) diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx index 3bc2c6438e..cff1d86d7e 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item/components/edit-item-form.tsx @@ -1,10 +1,7 @@ import * as zod from "zod" import { Button, Input, toast } from "@medusajs/ui" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../../components/modals" import { zodResolver } from "@hookform/resolvers/zod" import { InventoryTypes } from "@medusajs/types" @@ -44,17 +41,10 @@ export const EditInventoryItemForm = ({ item }: EditInventoryItemFormProps) => { const handleSubmit = form.handleSubmit(async (values) => { mutateAsync(values as any, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("inventory.toast.update"), - dismissLabel: t("actions.close"), - }) + toast.success(t("inventory.toast.updateItem")) handleSuccess() }, - onError: (e) => - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }), + onError: (e) => toast.error(e.message), }) }) diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx index 17a8b7b35a..7723d29931 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/manage-locations/components/manage-locations-form.tsx @@ -6,14 +6,11 @@ import { Button, Text, toast } from "@medusajs/ui" import { useFieldArray, useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../../components/modals" import { useBatchUpdateInventoryLevels } from "../../../../../../hooks/api/inventory" -import { LocationItem } from "./location-item" import { useEffect, useMemo } from "react" +import { LocationItem } from "./location-item" type EditInventoryItemAttributeFormProps = { item: AdminInventoryItem @@ -102,26 +99,23 @@ export const ManageLocationsForm = ({ return handleSuccess() } - try { - await mutateAsync({ + await mutateAsync( + { create: selectedLocations.map((location_id) => ({ location_id, })), delete: unselectedLocations, - }) - - handleSuccess() - - toast.success(t("general.success"), { - description: t("inventory.toast.updateLocations"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("inventory.toast.updateLocations")) + handleSuccess() + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) }) return ( diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx index 762eb6e6d8..b862f1cedd 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/reservations-table/reservation-actions.tsx @@ -1,10 +1,10 @@ import { PencilSquare, Trash } from "@medusajs/icons" import { toast, usePrompt } from "@medusajs/ui" -import { ActionMenu } from "../../../../../components/common/action-menu" import { InventoryTypes } from "@medusajs/types" -import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" import { useTranslation } from "react-i18next" +import { ActionMenu } from "../../../../../components/common/action-menu" +import { useDeleteReservationItem } from "../../../../../hooks/api/reservations" export const ReservationActions = ({ reservation, @@ -29,10 +29,10 @@ export const ReservationActions = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - dismissLabel: t("actions.close"), - description: t("inventory.reservation.deleteSuccessToast"), - }) + toast.success(t("inventory.reservation.deleteSuccessToast")) + }, + onError: (e) => { + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/invite/invite.tsx b/packages/admin-next/dashboard/src/routes/invite/invite.tsx index ba083dae65..65ad1761b0 100644 --- a/packages/admin-next/dashboard/src/routes/invite/invite.tsx +++ b/packages/admin-next/dashboard/src/routes/invite/invite.tsx @@ -1,19 +1,18 @@ import { zodResolver } from "@hookform/resolvers/zod" -import { UserRoles } from "@medusajs/medusa" import { Alert, Button, Heading, Input, Text, toast } from "@medusajs/ui" import { AnimatePresence, motion } from "framer-motion" -import { Trans, useTranslation } from "react-i18next" -import { Link, useSearchParams } from "react-router-dom" -import * as z from "zod" import i18n from "i18next" import { useState } from "react" import { useForm } from "react-hook-form" +import { Trans, useTranslation } from "react-i18next" import { decodeToken } from "react-jwt" +import { Link, useSearchParams } from "react-router-dom" +import * as z from "zod" import { Form } from "../../components/common/form" import { LogoBox } from "../../components/common/logo-box" -import { isAxiosError } from "../../lib/is-axios-error" -import { useAcceptInvite } from "../../hooks/api/invites" import { useCreateAuthUser } from "../../hooks/api/auth" +import { useAcceptInvite } from "../../hooks/api/invites" +import { isFetchError } from "../../lib/is-fetch-error" const CreateAccountSchema = z .object({ @@ -33,9 +32,10 @@ const CreateAccountSchema = z } }) +// TODO: Update to V2 format type DecodedInvite = { id: string - jti: UserRoles + jti: any exp: string iat: number } @@ -227,13 +227,12 @@ const CreateView = ({ ...invitePayload, auth_token: authToken, }) + + toast.success(t("invite.toast.accepted")) + onSuccess() - toast.success(t("general.success"), { - description: t("invite.toast.accepted"), - dismissLabel: t("actions.close"), - }) } catch (error) { - if (isAxiosError(error) && error.response?.status === 400) { + if (isFetchError(error) && error.status === 400) { form.setError("root", { type: "manual", message: t("invite.invalidInvite"), diff --git a/packages/admin-next/dashboard/src/routes/locations/location-create/components/create-location-form/create-location-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-create/components/create-location-form/create-location-form.tsx index 6ddf8b3d8b..cee229529b 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-create/components/create-location-form/create-location-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-create/components/create-location-form/create-location-form.tsx @@ -56,20 +56,12 @@ export const CreateLocationForm = () => { }, { onSuccess: ({ stock_location }) => { - toast.success(t("general.success"), { - description: t("locations.toast.create"), - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.success(t("locations.toast.create")) handleSuccess(`/settings/locations/${stock_location.id}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx b/packages/admin-next/dashboard/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx index f379b0b0a0..0187d9ec49 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-detail/components/location-general-section/location-general-section.tsx @@ -127,20 +127,14 @@ function ShippingOption({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.shippingOptions.delete.successToast", { + toast.success( + t("stockLocations.shippingOptions.delete.successToast", { name: option.name, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, }) } @@ -303,18 +297,14 @@ function ServiceZone({ zone, locationId, fulfillmentSetId }: ServiceZoneProps) { await deleteZone(undefined, { onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.serviceZones.delete.successToast", { + toast.success( + t("stockLocations.serviceZones.delete.successToast", { name: zone.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) }, }) } @@ -473,18 +463,10 @@ function FulfillmentSet(props: FulfillmentSetProps) { }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t(`stockLocations.fulfillmentSets.enable.${type}`), - dismissLabel: t("actions.close"), - dismissable: true, - }) + toast.success(t(`stockLocations.fulfillmentSets.enable.${type}`)) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - dismissable: true, - }) + toast.error(e.message) }, } ) @@ -506,18 +488,10 @@ function FulfillmentSet(props: FulfillmentSetProps) { await deleteFulfillmentSet(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t(`stockLocations.fulfillmentSets.disable.${type}`), - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.success(t(`stockLocations.fulfillmentSets.disable.${type}`)) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, }) } @@ -627,21 +601,15 @@ const Actions = ({ location }: { location: HttpTypes.AdminStockLocation }) => { await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.create.successToast", { + toast.success( + t("stockLocations.create.successToast", { name: location.name, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) navigate("/settings/locations", { replace: true }) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx index 38228b9309..7ac0d0cfc4 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx @@ -7,10 +7,7 @@ import * as zod from "zod" import { Form } from "../../../../../components/common/form" import { CountrySelect } from "../../../../../components/inputs/country-select" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateStockLocation } from "../../../../../hooks/api/stock-locations" type EditLocationFormProps = { @@ -64,18 +61,11 @@ export const EditLocationForm = ({ location }: EditLocationFormProps) => { }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.edit.successToast"), - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.success(t("stockLocations.edit.successToast")) handleSuccess() }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-list/components/location-list-item/location-list-item.tsx b/packages/admin-next/dashboard/src/routes/locations/location-list/components/location-list-item/location-list-item.tsx index b3bd548527..49a1162d4f 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-list/components/location-list-item/location-list-item.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-list/components/location-list-item/location-list-item.tsx @@ -105,18 +105,14 @@ function LocationListItem(props: LocationProps) { await deleteLocation(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("shippingProfile.delete.successToast", { + toast.success( + t("shippingProfile.delete.successToast", { name: location.name, - }), - dismissLabel: t("general.close"), - }) + }) + ) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx index ee6aef799f..2b0f60b84c 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-sales-channels/components/edit-sales-channels-form/edit-sales-channels-form.tsx @@ -107,19 +107,11 @@ export const LocationEditSalesChannelsForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.salesChannels.successToast"), - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.success(t("stockLocations.salesChannels.successToast")) handleSuccess(`/settings/locations/${location.id}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx index d117d7be0a..6472504b03 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx @@ -63,24 +63,16 @@ export function CreateServiceZoneForm({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.serviceZones.create.successToast", { + toast.success( + t("stockLocations.serviceZones.create.successToast", { name: data.name, - }), - dismissable: true, - dismissLabel: t("general.close"), - }) + }) + ) handleSuccess(`/settings/locations/${location.id}`) }, onError: (e) => { - console.error(e) - - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("general.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx index a82fcaf7e3..eaef714ebf 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx @@ -6,10 +6,7 @@ import * as zod from "zod" import { Form } from "../../../../../components/common/form" import { InlineTip } from "../../../../../components/common/inline-tip" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateFulfillmentSetServiceZone } from "../../../../../hooks/api/fulfillment-sets" type EditServiceZoneFormProps = { @@ -46,19 +43,15 @@ export const EditServiceZoneForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("stockLocations.serviceZones.edit.successToast", { + toast.success( + t("stockLocations.serviceZones.edit.successToast", { name: values.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/settings/locations/${locationId}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx index affd197c2d..37c9b13f52 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-manage-areas/components/edit-region-areas-form/edit-service-zone-areas-form.tsx @@ -63,25 +63,16 @@ export function EditServiceZoneAreasForm({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t( - "stockLocations.serviceZones.manageAreas.successToast", - { - name: zone.name, - } - ), - dismissable: true, - dismissLabel: t("general.close"), - }) + toast.success( + t("stockLocations.serviceZones.manageAreas.successToast", { + name: zone.name, + }) + ) handleSuccess(`/settings/locations/${locationId}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("general.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx index dcdca698a2..e69cff583d 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx @@ -113,27 +113,21 @@ export function CreateShippingOptionsForm({ }, { onSuccess: ({ shipping_option }) => { - toast.success(t("general.success"), { - description: t( + toast.success( + t( `stockLocations.shippingOptions.create.${ isReturn ? "returns" : "shipping" }.successToast`, { name: shipping_option.name, } - ), - dismissable: true, - dismissLabel: t("general.close"), - }) + ) + ) handleSuccess(`/settings/locations/${locationId}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-edit/components/edit-region-form/edit-shipping-option-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-edit/components/edit-region-form/edit-shipping-option-form.tsx index 50b9f8c0d3..3a42fe0139 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-edit/components/edit-region-form/edit-shipping-option-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-edit/components/edit-region-form/edit-shipping-option-form.tsx @@ -8,10 +8,7 @@ import { Divider } from "../../../../../components/common/divider" import { Form } from "../../../../../components/common/form" import { SwitchBox } from "../../../../../components/common/switch-box" import { Combobox } from "../../../../../components/inputs/combobox" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateShippingOptions } from "../../../../../hooks/api/shipping-options" import { useComboboxData } from "../../../../../hooks/use-combobox-data" import { sdk } from "../../../../../lib/client" @@ -104,21 +101,15 @@ export const EditShippingOptionForm = ({ }, { onSuccess: ({ shipping_option }) => { - toast.success(t("general.success"), { - description: t("stockLocations.shippingOptions.edit.successToast", { + toast.success( + t("stockLocations.shippingOptions.edit.successToast", { name: shipping_option.name, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess(`/settings/locations/${locationId}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-pricing/components/create-shipping-options-form/edit-shipping-options-pricing-form.tsx b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-pricing/components/create-shipping-options-form/edit-shipping-options-pricing-form.tsx index e36d8fd271..64b0809793 100644 --- a/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-pricing/components/create-shipping-options-form/edit-shipping-options-pricing-form.tsx +++ b/packages/admin-next/dashboard/src/routes/locations/location-service-zone-shipping-option-pricing/components/create-shipping-options-form/edit-shipping-options-pricing-form.tsx @@ -186,16 +186,11 @@ export function EditShippingOptionsPricingForm({ }, { onSuccess: () => { - toast.success(t("general.success"), { - dismissLabel: t("general.close"), - }) + toast.success(t("general.success")) handleSuccess() }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("general.close"), - }) + toast.error(e.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-form.tsx index d71c6dada6..26b29426fb 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-form.tsx @@ -66,17 +66,10 @@ export function OrderCreateFulfillmentForm({ })), }) + toast.success(t("orders.fulfillment.toast.created")) handleSuccess(`/orders/${order.id}`) - - toast.success(t("general.success"), { - description: t("orders.fulfillment.toast.created"), - dismissLabel: t("actions.close"), - }) } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) } }) diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-shipment/components/order-create-shipment-form/order-create-shipment-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-shipment/components/order-create-shipment-form/order-create-shipment-form.tsx index f98ff56fcb..55fc5500a1 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-shipment/components/order-create-shipment-form/order-create-shipment-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-shipment/components/order-create-shipment-form/order-create-shipment-form.tsx @@ -11,9 +11,8 @@ import { RouteFocusModal, useRouteModal, } from "../../../../../components/modals" -import { useCreateOrderShipment } from "../../../../../hooks/api/orders" -import { CreateShipmentSchema } from "./constants" import { useCreateShipment } from "../../../../../hooks/api/fulfillment.tsx" +import { CreateShipmentSchema } from "./constants" type OrderCreateFulfillmentFormProps = { order: AdminOrder @@ -33,7 +32,7 @@ export function OrderCreateShipmentForm({ const form = useForm>({ defaultValues: { labels: [{ tracking_number: "" }], - send_notification: !order.no_notification, //TODO: not supported in the API + send_notification: !order.no_notification, // TODO: not supported in the API }, resolver: zodResolver(CreateShipmentSchema), }) @@ -44,8 +43,8 @@ export function OrderCreateShipmentForm({ }) const handleSubmit = form.handleSubmit(async (data) => { - try { - await createShipment({ + await createShipment( + { labels: data.labels .filter((l) => !!l.tracking_number) .map((l) => ({ @@ -54,20 +53,17 @@ export function OrderCreateShipmentForm({ label_url: "#", })), // no_notification: !data.send_notification, - }) - - handleSuccess(`/orders/${order.id}`) - - toast.success(t("general.success"), { - description: t("orders.shipment.toastCreated"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("orders.shipment.toastCreated")) + handleSuccess(`/orders/${order.id}`) + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) }) return ( @@ -99,6 +95,7 @@ export function OrderCreateShipmentForm({ {labels.map((label, index) => ( { diff --git a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-fulfillment-section/order-fulfillment-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-fulfillment-section/order-fulfillment-section.tsx index eefbc6c1fe..9e9074b807 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-fulfillment-section/order-fulfillment-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-detail/components/order-fulfillment-section/order-fulfillment-section.tsx @@ -1,6 +1,7 @@ import { Buildings, XCircle } from "@medusajs/icons" import { AdminOrder, FulfillmentDTO, OrderLineItemDTO } from "@medusajs/types" import { + Button, Container, Copy, Heading, @@ -9,7 +10,6 @@ import { Tooltip, toast, usePrompt, - Button, } from "@medusajs/ui" import { format } from "date-fns" import { useTranslation } from "react-i18next" @@ -17,10 +17,10 @@ import { Link, useNavigate } from "react-router-dom" import { ActionMenu } from "../../../../../components/common/action-menu" import { Skeleton } from "../../../../../components/common/skeleton" import { Thumbnail } from "../../../../../components/common/thumbnail" +import { useCancelOrderFulfillment } from "../../../../../hooks/api/orders" import { useStockLocation } from "../../../../../hooks/api/stock-locations" import { formatProvider } from "../../../../../lib/format-provider" import { getLocaleAmount } from "../../../../../lib/money-amount-helpers" -import { useCancelOrderFulfillment } from "../../../../../hooks/api/orders" type OrderFulfillmentSectionProps = { order: AdminOrder @@ -190,10 +190,7 @@ const Fulfillment = ({ const handleCancel = async () => { if (fulfillment.shipped_at) { - toast.warning(t("general.warning"), { - description: t("orders.fulfillment.toast.fulfillmentShipped"), - dismissLabel: t("actions.close"), - }) + toast.warning(t("orders.fulfillment.toast.fulfillmentShipped")) return } @@ -205,19 +202,14 @@ const Fulfillment = ({ }) if (res) { - try { - await mutateAsync() - - toast.success(t("general.success"), { - description: t("orders.fulfillment.toast.canceled"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + await mutateAsync(undefined, { + onSuccess: () => { + toast.success(t("orders.fulfillment.toast.canceled")) + }, + onError: (e) => { + toast.error(e.message) + }, + }) } } diff --git a/packages/admin-next/dashboard/src/routes/price-lists/common/hooks/use-delete-price-list-action.tsx b/packages/admin-next/dashboard/src/routes/price-lists/common/hooks/use-delete-price-list-action.tsx index 0619bd1061..9c42b50f7d 100644 --- a/packages/admin-next/dashboard/src/routes/price-lists/common/hooks/use-delete-price-list-action.tsx +++ b/packages/admin-next/dashboard/src/routes/price-lists/common/hooks/use-delete-price-list-action.tsx @@ -32,22 +32,16 @@ export const useDeletePriceListAction = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("priceLists.delete.successToast", { + toast.success( + t("priceLists.delete.successToast", { name: priceList.title, - }), - dismissable: true, - dismissLabel: t("actions.close"), - }) + }) + ) navigate("/price-lists") }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/product-types/common/hooks/use-delete-product-type-action.tsx b/packages/admin-next/dashboard/src/routes/product-types/common/hooks/use-delete-product-type-action.tsx index 4eb9cb2690..70fd55ff34 100644 --- a/packages/admin-next/dashboard/src/routes/product-types/common/hooks/use-delete-product-type-action.tsx +++ b/packages/admin-next/dashboard/src/routes/product-types/common/hooks/use-delete-product-type-action.tsx @@ -22,18 +22,10 @@ export const useDeleteProductTypeAction = (id: string) => { await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("productTypes.delete.successToast"), - dismissLabel: t("actions.close"), - dismissable: true, - }) + toast.success(t("productTypes.delete.successToast")) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - dismissable: true, - }) + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/product-types/product-type-create/components/create-product-type-form/create-product-type-form.tsx b/packages/admin-next/dashboard/src/routes/product-types/product-type-create/components/create-product-type-form/create-product-type-form.tsx index d5d62b92e6..036e4d7813 100644 --- a/packages/admin-next/dashboard/src/routes/product-types/product-type-create/components/create-product-type-form/create-product-type-form.tsx +++ b/packages/admin-next/dashboard/src/routes/product-types/product-type-create/components/create-product-type-form/create-product-type-form.tsx @@ -31,22 +31,16 @@ export const CreateProductTypeForm = () => { async (values: z.infer) => { await mutateAsync(values, { onSuccess: ({ product_type }) => { - toast.success(t("general.success"), { - description: t("productTypes.create.successToast", { + toast.success( + t("productTypes.create.successToast", { value: product_type.value, - }), - dismissLabel: t("actions.close"), - dismissable: true, - }) + }) + ) handleSuccess(`/settings/product-types/${product_type.id}`) }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - dismissable: true, - }) + toast.error(e.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/product-types/product-type-edit/components/edit-product-type-form/edit-product-type-form.tsx b/packages/admin-next/dashboard/src/routes/product-types/product-type-edit/components/edit-product-type-form/edit-product-type-form.tsx index 9f76269eed..5093eb0b8c 100644 --- a/packages/admin-next/dashboard/src/routes/product-types/product-type-edit/components/edit-product-type-form/edit-product-type-form.tsx +++ b/packages/admin-next/dashboard/src/routes/product-types/product-type-edit/components/edit-product-type-form/edit-product-type-form.tsx @@ -5,10 +5,7 @@ import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" import { Form } from "../../../../../components/common/form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateProductType } from "../../../../../hooks/api/product-types" const EditProductTypeSchema = z.object({ @@ -41,21 +38,15 @@ export const EditProductTypeForm = ({ }, { onSuccess: ({ product_type }) => { - toast.success(t("general.success"), { - description: t("productTypes.edit.successToast", { + toast.success( + t("productTypes.edit.successToast", { value: product_type.value, - }), - dismissable: true, - dismissLabel: t("general.close"), - }) + }) + ) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissable: true, - dismissLabel: t("general.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/product-variants/product-variant-manage-inventory-items/components/manage-variant-inventory-items-form/manage-variant-inventory-items-form.tsx b/packages/admin-next/dashboard/src/routes/product-variants/product-variant-manage-inventory-items/components/manage-variant-inventory-items-form/manage-variant-inventory-items-form.tsx index 35321c9ba4..852c1aa886 100644 --- a/packages/admin-next/dashboard/src/routes/product-variants/product-variant-manage-inventory-items/components/manage-variant-inventory-items-form/manage-variant-inventory-items-form.tsx +++ b/packages/admin-next/dashboard/src/routes/product-variants/product-variant-manage-inventory-items/components/manage-variant-inventory-items-form/manage-variant-inventory-items-form.tsx @@ -16,7 +16,6 @@ import { import { useProductVariantsInventoryItemsBatch } from "../../../../../hooks/api/products" import { useComboboxData } from "../../../../../hooks/use-combobox-data" import { sdk } from "../../../../../lib/client" -import { useEffect } from "react" type ManageVariantInventoryItemsFormProps = { variant: AdminProductVariant & { @@ -141,17 +140,11 @@ export function ManageVariantInventoryItemsForm({ await mutateAsync(payload, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("products.variant.inventory.toast.itemsManageSuccess"), - dismissLabel: t("general.close"), - }) + toast.success(t("products.variant.inventory.toast.itemsManageSuccess")) handleSuccess() }, onError: (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) }) diff --git a/packages/admin-next/dashboard/src/routes/products/product-create-option/components/create-product-option-form/create-product-option-form.tsx b/packages/admin-next/dashboard/src/routes/products/product-create-option/components/create-product-option-form/create-product-option-form.tsx index be8d3f9af5..c7351ca948 100644 --- a/packages/admin-next/dashboard/src/routes/products/product-create-option/components/create-product-option-form/create-product-option-form.tsx +++ b/packages/admin-next/dashboard/src/routes/products/product-create-option/components/create-product-option-form/create-product-option-form.tsx @@ -7,10 +7,7 @@ import { z } from "zod" import { HttpTypes } from "@medusajs/types" import { Form } from "../../../../../components/common/form" import { ChipInput } from "../../../../../components/inputs/chip-input" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useCreateProductOption } from "../../../../../hooks/api/products" type EditProductOptionsFormProps = { @@ -41,19 +38,15 @@ export const CreateProductOptionForm = ({ const handleSubmit = form.handleSubmit(async (values) => { mutateAsync(values, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("products.options.create.successToast", { + toast.success( + t("products.options.create.successToast", { title: values.title, - }), - dismissLabel: t("general.close"), - }) + }) + ) handleSuccess() }, onError: async (err) => { - toast.error(t("general.error"), { - description: err.message, - dismissLabel: t("general.close"), - }) + toast.error(err.message) }, }) }) diff --git a/packages/admin-next/dashboard/src/routes/products/product-create/components/product-create-form/product-create-form.tsx b/packages/admin-next/dashboard/src/routes/products/product-create/components/product-create-form/product-create-form.tsx index 0512644a91..35ef514039 100644 --- a/packages/admin-next/dashboard/src/routes/products/product-create/components/product-create-form/product-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/products/product-create/components/product-create-form/product-create-form.tsx @@ -91,79 +91,69 @@ export const ProductCreateForm = ({ [watchedVariants] ) - const handleSubmit = form.handleSubmit( - async (values, e) => { - let isDraftSubmission = false - if (e?.nativeEvent instanceof SubmitEvent) { - const submitter = e?.nativeEvent?.submitter as HTMLButtonElement - isDraftSubmission = submitter.dataset.name === SAVE_DRAFT_BUTTON - } - - const media = values.media || [] - const payload = { ...values, media: undefined } - - let uploadedMedia: (HttpTypes.AdminFile & { isThumbnail: boolean })[] = [] - try { - if (media.length) { - const thumbnailReq = media.find((m) => m.isThumbnail) - const otherMediaReq = media.filter((m) => !m.isThumbnail) - - const fileReqs = [] - if (thumbnailReq) { - fileReqs.push( - sdk.admin.upload - .create({ files: [thumbnailReq.file] }) - .then((r) => r.files.map((f) => ({ ...f, isThumbnail: true }))) - ) - } - if (otherMediaReq?.length) { - fileReqs.push( - sdk.admin.upload - .create({ - files: otherMediaReq.map((m) => m.file), - }) - .then((r) => r.files.map((f) => ({ ...f, isThumbnail: false }))) - ) - } - - uploadedMedia = (await Promise.all(fileReqs)).flat() - } - - const { product } = await mutateAsync( - normalizeProductFormValues({ - ...payload, - media: uploadedMedia, - status: (isDraftSubmission ? "draft" : "published") as any, - regionsCurrencyMap, - }) - ) - - toast.success(t("general.success"), { - dismissLabel: t("actions.close"), - description: t("products.create.successToast", { - title: product.title, - }), - }) - - handleSuccess(`../${product.id}`) - } catch (error) { - if (isFetchError(error) && error.status === 400) { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("general.close"), - }) - } else { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("general.close"), - }) - } - } - }, - (err) => { - console.log(err) + const handleSubmit = form.handleSubmit(async (values, e) => { + let isDraftSubmission = false + if (e?.nativeEvent instanceof SubmitEvent) { + const submitter = e?.nativeEvent?.submitter as HTMLButtonElement + isDraftSubmission = submitter.dataset.name === SAVE_DRAFT_BUTTON } - ) + + const media = values.media || [] + const payload = { ...values, media: undefined } + + let uploadedMedia: (HttpTypes.AdminFile & { isThumbnail: boolean })[] = [] + try { + if (media.length) { + const thumbnailReq = media.find((m) => m.isThumbnail) + const otherMediaReq = media.filter((m) => !m.isThumbnail) + + const fileReqs = [] + if (thumbnailReq) { + fileReqs.push( + sdk.admin.upload + .create({ files: [thumbnailReq.file] }) + .then((r) => r.files.map((f) => ({ ...f, isThumbnail: true }))) + ) + } + if (otherMediaReq?.length) { + fileReqs.push( + sdk.admin.upload + .create({ + files: otherMediaReq.map((m) => m.file), + }) + .then((r) => r.files.map((f) => ({ ...f, isThumbnail: false }))) + ) + } + + uploadedMedia = (await Promise.all(fileReqs)).flat() + } + + const { product } = await mutateAsync( + normalizeProductFormValues({ + ...payload, + media: uploadedMedia, + status: (isDraftSubmission ? "draft" : "published") as any, + regionsCurrencyMap, + }) + ) + + toast.success( + t("products.create.successToast", { + title: product.title, + }) + ) + + handleSuccess(`../${product.id}`) + } catch (error) { + if (isFetchError(error) && error.status === 400) { + toast.error(error.message) + } else { + toast.error(t("general.error"), { + description: error.message, + }) + } + } + }) const onNext = async (currentTab: Tab) => { const valid = await form.trigger() diff --git a/packages/admin-next/dashboard/src/routes/products/product-list/components/product-list-table/product-list-table.tsx b/packages/admin-next/dashboard/src/routes/products/product-list/components/product-list-table/product-list-table.tsx index 2922180bd6..26e08f8a52 100644 --- a/packages/admin-next/dashboard/src/routes/products/product-list/components/product-list-table/product-list-table.tsx +++ b/packages/admin-next/dashboard/src/routes/products/product-list/components/product-list-table/product-list-table.tsx @@ -109,13 +109,11 @@ const ProductActions = ({ product }: { product: HttpTypes.AdminProduct }) => { description: t("products.toasts.delete.success.description", { title: product.title, }), - dismissLabel: t("actions.close"), }) }, onError: (e) => { toast.error(t("products.toasts.delete.error.header"), { description: e.message, - dismissLabel: t("actions.close"), }) }, }) diff --git a/packages/admin-next/dashboard/src/routes/products/product-organization/components/product-organization-form/product-organization-form.tsx b/packages/admin-next/dashboard/src/routes/products/product-organization/components/product-organization-form/product-organization-form.tsx index 3e519cc4c7..0e6171c04b 100644 --- a/packages/admin-next/dashboard/src/routes/products/product-organization/components/product-organization-form/product-organization-form.tsx +++ b/packages/admin-next/dashboard/src/routes/products/product-organization/components/product-organization-form/product-organization-form.tsx @@ -6,10 +6,7 @@ import { useTranslation } from "react-i18next" import * as zod from "zod" import { Form } from "../../../../../components/common/form" import { Combobox } from "../../../../../components/inputs/combobox" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateProduct } from "../../../../../hooks/api/products" import { useComboboxData } from "../../../../../hooks/use-combobox-data" import { client, sdk } from "../../../../../lib/client" @@ -87,19 +84,15 @@ export const ProductOrganizationForm = ({ }, { onSuccess: ({ product }) => { - toast.success(t("general.success"), { - description: t("products.organization.edit.toasts.success", { + toast.success( + t("products.organization.edit.toasts.success", { title: product.title, - }), - }) + }) + ) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissable: true, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/profile/profile-edit/components/edit-profile-form/edit-profile-form.tsx b/packages/admin-next/dashboard/src/routes/profile/profile-edit/components/edit-profile-form/edit-profile-form.tsx index 78aa60581f..e297fc8d7d 100644 --- a/packages/admin-next/dashboard/src/routes/profile/profile-edit/components/edit-profile-form/edit-profile-form.tsx +++ b/packages/admin-next/dashboard/src/routes/profile/profile-edit/components/edit-profile-form/edit-profile-form.tsx @@ -6,10 +6,7 @@ import * as zod from "zod" import { UserDTO } from "@medusajs/types" import { Form } from "../../../../../components/common/form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateUser } from "../../../../../hooks/api/users" import { languages } from "../../../../../i18n/languages" @@ -58,17 +55,10 @@ export const EditProfileForm = ({ user, usageInsights }: EditProfileProps) => { await changeLanguage(values.language) + toast.success(t("profile.toast.edit")) handleSuccess() - - toast.success(t("general.success"), { - description: t("profile.toast.edit"), - dismissLabel: t("actions.close"), - }) } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) } }) diff --git a/packages/admin-next/dashboard/src/routes/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx b/packages/admin-next/dashboard/src/routes/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx index a0be315ecd..e221e239e7 100644 --- a/packages/admin-next/dashboard/src/routes/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx +++ b/packages/admin-next/dashboard/src/routes/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx @@ -136,20 +136,16 @@ export const CreatePromotionForm = () => { }, { onSuccess: ({ promotion }) => { - toast.success(t("general.success"), { - description: t("promotions.toasts.promotionCreateSuccess", { + toast.success( + t("promotions.toasts.promotionCreateSuccess", { code: promotion.code, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess() }, onError: (e) => { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + toast.error(e.message) }, } ) @@ -159,10 +155,7 @@ export const CreatePromotionForm = () => { const errorInPromotionTab = !!Object.keys(rest || {}).length if (errorInPromotionTab) { - toast.error(t("general.error"), { - description: t("promotions.errors.promotionTabError"), - dismissLabel: t("general.close"), - }) + toast.error(t("promotions.errors.promotionTabError")) } } ) diff --git a/packages/admin-next/dashboard/src/routes/regions/region-add-countries/components/add-countries-form/add-countries-form.tsx b/packages/admin-next/dashboard/src/routes/regions/region-add-countries/components/add-countries-form/add-countries-form.tsx index 8f90a81214..3c8efd8950 100644 --- a/packages/admin-next/dashboard/src/routes/regions/region-add-countries/components/add-countries-form/add-countries-form.tsx +++ b/packages/admin-next/dashboard/src/routes/regions/region-add-countries/components/add-countries-form/add-countries-form.tsx @@ -102,27 +102,24 @@ export const AddCountriesForm = ({ region }: AddCountriesFormProps) => { const handleSubmit = form.handleSubmit(async (values) => { const payload = [ - ...(region.countries?.map((c) => c.iso_2) ?? []), + ...(region.countries?.map((c) => c.iso_2!) ?? []), ...values.countries, ] - try { - await mutateAsync({ + await mutateAsync( + { countries: payload, - }) - - handleSuccess() - - toast.success(t("general.success"), { - description: t("regions.toast.countries"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("regions.toast.countries")) + handleSuccess() + }, + onError: (error) => { + toast.error(error.message) + }, + } + ) }) return ( diff --git a/packages/admin-next/dashboard/src/routes/regions/region-create/components/create-region-form/create-region-form.tsx b/packages/admin-next/dashboard/src/routes/regions/region-create/components/create-region-form/create-region-form.tsx index 740b3dd638..4863280cf1 100644 --- a/packages/admin-next/dashboard/src/routes/regions/region-create/components/create-region-form/create-region-form.tsx +++ b/packages/admin-next/dashboard/src/routes/regions/region-create/components/create-region-form/create-region-form.tsx @@ -102,13 +102,12 @@ export const CreateRegionForm = ({ }) }, onSuccess: ({ region }) => { - toast.success(t("general.success"), { - description: t("regions.toast.create"), - dismissLabel: t("actions.close"), - }) - + toast.success(t("regions.toast.create")) handleSuccess(`../${region.id}`) }, + onError: (e) => { + toast.error(e.message) + }, } ) }) diff --git a/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-country-section/region-country-section.tsx b/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-country-section/region-country-section.tsx index da4d09c970..b1f8fc6d4b 100644 --- a/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-country-section/region-country-section.tsx +++ b/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-country-section/region-country-section.tsx @@ -1,4 +1,5 @@ import { PlusMini, Trash } from "@medusajs/icons" +import { HttpTypes } from "@medusajs/types" import { Checkbox, Container, Heading, toast, usePrompt } from "@medusajs/ui" import { ColumnDef, @@ -9,12 +10,11 @@ import { useMemo, useState } from "react" import { useTranslation } from "react-i18next" import { ActionMenu } from "../../../../../components/common/action-menu" import { DataTable } from "../../../../../components/table/data-table" +import { useUpdateRegion } from "../../../../../hooks/api/regions" import { useDataTable } from "../../../../../hooks/use-data-table" import { useCountries } from "../../../common/hooks/use-countries" import { useCountryTableColumns } from "../../../common/hooks/use-country-table-columns" import { useCountryTableQuery } from "../../../common/hooks/use-country-table-query" -import { useUpdateRegion } from "../../../../../hooks/api/regions" -import { HttpTypes } from "@medusajs/types" type RegionCountrySectionProps = { region: HttpTypes.AdminRegion @@ -79,24 +79,22 @@ export const RegionCountrySection = ({ region }: RegionCountrySectionProps) => { } const payload = region.countries - .filter((c) => !ids.includes(c.iso_2)) - .map((c) => c.iso_2) + ?.filter((c) => !ids.includes(c.iso_2!)) + .map((c) => c.iso_2!) - try { - await mutateAsync({ + await mutateAsync( + { countries: payload, - }) - - toast.success(t("general.success"), { - description: t("regions.toast.countries"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("regions.toast.countries")) + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) } return ( @@ -170,21 +168,19 @@ const CountryActions = ({ return } - try { - await mutateAsync({ + await mutateAsync( + { countries: payload, - }) - - toast.success(t("general.success"), { - description: t("regions.toast.countries"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("regions.toast.countries")) + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) } return ( diff --git a/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-general-section/region-general-section.tsx b/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-general-section/region-general-section.tsx index c2af73d279..12eee57d60 100644 --- a/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-general-section/region-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/regions/region-detail/components/region-general-section/region-general-section.tsx @@ -100,19 +100,15 @@ const RegionActions = ({ region }: { region: HttpTypes.AdminRegion }) => { return } - try { - await mutateAsync(undefined) - toast.success(t("general.success"), { - description: t("regions.toast.delete"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } - navigate("/settings/regions", { replace: true }) + await mutateAsync(undefined, { + onSuccess: () => { + toast.success(t("regions.toast.delete")) + navigate("/settings/regions", { replace: true }) + }, + onError: (e) => { + toast.error(e.message) + }, + }) } return ( diff --git a/packages/admin-next/dashboard/src/routes/regions/region-edit/components/edit-region-form/edit-region-form.tsx b/packages/admin-next/dashboard/src/routes/regions/region-edit/components/edit-region-form/edit-region-form.tsx index 3c5ea2d50a..5c42c1dbe3 100644 --- a/packages/admin-next/dashboard/src/routes/regions/region-edit/components/edit-region-form/edit-region-form.tsx +++ b/packages/admin-next/dashboard/src/routes/regions/region-edit/components/edit-region-form/edit-region-form.tsx @@ -71,12 +71,12 @@ export const EditRegionForm = ({ }) }, onSuccess: () => { - toast.success(t("general.success"), { - description: t("regions.toast.edit"), - dismissLabel: t("actions.close"), - }) + toast.success(t("regions.toast.edit")) handleSuccess() }, + onError: (e) => { + toast.error(e.message) + }, } ) }) diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx index ad0f445c76..029cc52d72 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/components/edit-reservation/components/edit-reservation-form.tsx @@ -69,11 +69,11 @@ export const EditReservationForm = ({ const handleSubmit = form.handleSubmit(async (values) => { mutateAsync(values as any, { onSuccess: () => { + toast.success(t("inventory.reservation.updateSuccessToast")) handleSuccess() - toast.success(t("general.success"), { - dismissLabel: t("actions.close"), - description: t("inventory.reservation.updateSuccessToast"), - }) + }, + onError: (e) => { + toast.error(e.message) }, }) }) diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/create-reservation/components/create-reservation-form/create-reservation-form.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/create-reservation/components/create-reservation-form/create-reservation-form.tsx index fd5fd902e0..90eb1b2ca7 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/create-reservation/components/create-reservation-form/create-reservation-form.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/create-reservation/components/create-reservation-form/create-reservation-form.tsx @@ -94,16 +94,16 @@ export const CreateReservationForm = (props: { inventoryItemId?: string }) => { const handleSubmit = form.handleSubmit(async (data) => { await mutateAsync(data, { onSuccess: ({ reservation }) => { - toast.success(t("general.success"), { - dismissLabel: t("actions.close"), - description: t("inventory.reservation.successToast"), - }) + toast.success(t("inventory.reservation.successToast")) handleSuccess( props.inventoryItemId ? `/inventory/${props.inventoryItemId}` : `/reservations/${reservation.id}` ) }, + onError: (e) => { + toast.error(e.message) + }, }) }) diff --git a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-add-products/components/add-products-to-sales-channel-form.tsx b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-add-products/components/add-products-to-sales-channel-form.tsx index 896ea3113e..335dba1150 100644 --- a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-add-products/components/add-products-to-sales-channel-form.tsx +++ b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-add-products/components/add-products-to-sales-channel-form.tsx @@ -1,11 +1,11 @@ import { zodResolver } from "@hookform/resolvers/zod" import { HttpTypes, SalesChannelDTO } from "@medusajs/types" -import { Button, Checkbox, Hint, toast, Tooltip } from "@medusajs/ui" +import { Button, Checkbox, Hint, Tooltip, toast } from "@medusajs/ui" import { keepPreviousData } from "@tanstack/react-query" import { - createColumnHelper, OnChangeFn, RowSelectionState, + createColumnHelper, } from "@tanstack/react-table" import { useMemo, useState } from "react" import { useForm } from "react-hook-form" @@ -110,17 +110,10 @@ export const AddProductsToSalesChannelForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("salesChannels.toast.update"), - dismissLabel: t("actions.close"), - }) + toast.success(t("salesChannels.toast.update")) handleSuccess() }, - onError: (error) => - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }), + onError: (error) => toast.error(error.message), } ) }) diff --git a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-create/components/create-sales-channel-form/create-sales-channel-form.tsx b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-create/components/create-sales-channel-form/create-sales-channel-form.tsx index e45836d0d3..bbcd512356 100644 --- a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-create/components/create-sales-channel-form/create-sales-channel-form.tsx +++ b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-create/components/create-sales-channel-form/create-sales-channel-form.tsx @@ -48,17 +48,10 @@ export const CreateSalesChannelForm = () => { }, { onSuccess: ({ sales_channel }) => { - toast.success(t("general.success"), { - description: t("salesChannels.toast.create"), - dismissLabel: t("actions.close"), - }) + toast.success(t("salesChannels.toast.create")) handleSuccess(`../${sales_channel.id}`) }, - onError: (error) => - toast.success(t("general.success"), { - description: error.message, - dismissLabel: t("actions.close"), - }), + onError: (error) => toast.success(error.message), } ) }) diff --git a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-general-section/sales-channel-general-section.tsx b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-general-section/sales-channel-general-section.tsx index c0bfb19293..010608d1f8 100644 --- a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-general-section/sales-channel-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-general-section/sales-channel-general-section.tsx @@ -43,21 +43,15 @@ export const SalesChannelGeneralSection = ({ return } - try { - await mutateAsync() - - navigate("/settings/sales-channels", { replace: true }) - - toast.success(t("general.success"), { - description: t("salesChannels.toast.delete"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + await mutateAsync(undefined, { + onSuccess: () => { + toast.success(t("salesChannels.toast.delete")) + navigate("/settings/sales-channels", { replace: true }) + }, + onError: (e) => { + toast.error(e.message) + }, + }) } return ( diff --git a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-product-section/sales-channel-product-section.tsx b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-product-section/sales-channel-product-section.tsx index 1b921bd8a5..9ddff7edf5 100644 --- a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-product-section/sales-channel-product-section.tsx +++ b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-detail/components/sales-channel-product-section/sales-channel-product-section.tsx @@ -12,7 +12,7 @@ import { useMemo, useState } from "react" import { useTranslation } from "react-i18next" import { Link } from "react-router-dom" -import { SalesChannelDTO } from "@medusajs/types" +import { HttpTypes, SalesChannelDTO } from "@medusajs/types" import { keepPreviousData } from "@tanstack/react-query" import { ActionMenu } from "../../../../../components/common/action-menu" import { DataTable } from "../../../../../components/table/data-table" @@ -22,7 +22,6 @@ import { useProductTableColumns } from "../../../../../hooks/table/columns/use-p import { useProductTableFilters } from "../../../../../hooks/table/filters/use-product-table-filters" import { useProductTableQuery } from "../../../../../hooks/table/query/use-product-table-query" import { useDataTable } from "../../../../../hooks/use-data-table" -import { HttpTypes } from "@medusajs/types" const PAGE_SIZE = 10 @@ -100,17 +99,11 @@ export const SalesChannelProductSection = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("salesChannels.toast.update"), - dismissLabel: t("actions.close"), - }) + toast.success(t("salesChannels.toast.update")) setRowSelection({}) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) @@ -225,20 +218,19 @@ const ProductListCellActions = ({ const { mutateAsync } = useSalesChannelRemoveProducts(salesChannelId) const onRemove = async () => { - try { - await mutateAsync({ + await mutateAsync( + { product_ids: [productId], - }) - toast.success(t("general.success"), { - description: t("salesChannels.toast.update"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("salesChannels.toast.update")) + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) } return ( diff --git a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-edit/components/edit-sales-channel-form/edit-sales-channel-form.tsx b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-edit/components/edit-sales-channel-form/edit-sales-channel-form.tsx index adf6c5ce63..d4fe4dab7f 100644 --- a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-edit/components/edit-sales-channel-form/edit-sales-channel-form.tsx +++ b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-edit/components/edit-sales-channel-form/edit-sales-channel-form.tsx @@ -6,10 +6,7 @@ import * as zod from "zod" import { SalesChannelDTO } from "@medusajs/types" import { Form } from "../../../../../components/common/form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useUpdateSalesChannel } from "../../../../../hooks/api/sales-channels" type EditSalesChannelFormProps = { @@ -48,17 +45,11 @@ export const EditSalesChannelForm = ({ }, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("salesChannels.toast.update"), - dismissLabel: t("actions.close"), - }) + toast.success(t("salesChannels.toast.update")) handleSuccess() }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-list/components/sales-channel-list-table.tsx b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-list/components/sales-channel-list-table.tsx index 7312cf4019..6a4e8a908e 100644 --- a/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-list/components/sales-channel-list-table.tsx +++ b/packages/admin-next/dashboard/src/routes/sales-channels/sales-channel-list/components/sales-channel-list-table.tsx @@ -4,9 +4,9 @@ import { Button, Container, Heading, + Text, toast, usePrompt, - Text, } from "@medusajs/ui" import { keepPreviousData } from "@tanstack/react-query" import { createColumnHelper } from "@tanstack/react-table" @@ -112,18 +112,14 @@ const SalesChannelActions = ({ return } - try { - await mutateAsync() - toast.success(t("general.success"), { - description: t("salesChannels.toast.delete"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + await mutateAsync(undefined, { + onSuccess: () => { + toast.success(t("salesChannels.toast.delete")) + }, + onError: (e) => { + toast.error(e.message) + }, + }) } return ( diff --git a/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-create/components/create-shipping-profile-form/create-shipping-profile-form.tsx b/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-create/components/create-shipping-profile-form/create-shipping-profile-form.tsx index eaa0e7796c..13067287c2 100644 --- a/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-create/components/create-shipping-profile-form/create-shipping-profile-form.tsx +++ b/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-create/components/create-shipping-profile-form/create-shipping-profile-form.tsx @@ -38,22 +38,18 @@ export function CreateShippingProfileForm() { }, { onSuccess: ({ shipping_profile }) => { - toast.success(t("general.success"), { - description: t("shippingProfile.create.successToast", { + toast.success( + t("shippingProfile.create.successToast", { name: shipping_profile.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) handleSuccess( `/settings/locations/shipping-profiles/${shipping_profile.id}` ) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, } ) diff --git a/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-detail/components/shipping-profile-general-section/shipping-profile-general-section.tsx b/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-detail/components/shipping-profile-general-section/shipping-profile-general-section.tsx index 05ce6e10c5..c4d96a8190 100644 --- a/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-detail/components/shipping-profile-general-section/shipping-profile-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profile-detail/components/shipping-profile-general-section/shipping-profile-general-section.tsx @@ -38,20 +38,16 @@ export const ShippingProfileGeneralSection = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("shippingProfile.delete.successToast", { + toast.success( + t("shippingProfile.delete.successToast", { name: profile.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) navigate("/settings/locations/shipping-profiles", { replace: true }) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profiles-list/components/shipping-profile-list-table/shipping-options-row-actions.tsx b/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profiles-list/components/shipping-profile-list-table/shipping-options-row-actions.tsx index 00ca93bd2b..a17a7cd177 100644 --- a/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profiles-list/components/shipping-profile-list-table/shipping-options-row-actions.tsx +++ b/packages/admin-next/dashboard/src/routes/shipping-profiles/shipping-profiles-list/components/shipping-profile-list-table/shipping-options-row-actions.tsx @@ -34,18 +34,14 @@ export const ShippingOptionsRowActions = ({ await mutateAsync(undefined, { onSuccess: () => { - toast.success(t("general.success"), { - description: t("shippingProfile.delete.successToast", { + toast.success( + t("shippingProfile.delete.successToast", { name: profile.name, - }), - dismissLabel: t("actions.close"), - }) + }) + ) }, onError: (error) => { - toast.error(t("general.error"), { - description: error.message, - dismissLabel: t("actions.close"), - }) + toast.error(error.message) }, }) } diff --git a/packages/admin-next/dashboard/src/routes/store/store-add-currencies/components/add-currencies-form/add-currencies-form.tsx b/packages/admin-next/dashboard/src/routes/store/store-add-currencies/components/add-currencies-form/add-currencies-form.tsx index a08766a058..53ec9678f3 100644 --- a/packages/admin-next/dashboard/src/routes/store/store-add-currencies/components/add-currencies-form/add-currencies-form.tsx +++ b/packages/admin-next/dashboard/src/routes/store/store-add-currencies/components/add-currencies-form/add-currencies-form.tsx @@ -113,26 +113,25 @@ export const AddCurrenciesForm = ({ store }: AddCurrenciesFormProps) => { defaultCurrency = currencies?.[0] } - try { - await mutateAsync({ + await mutateAsync( + { supported_currencies: currencies.map((c) => ({ currency_code: c, is_default: c === defaultCurrency, // TODO: Add UI to manage this is_tax_inclsuive: false, })), - }) - toast.success(t("general.success"), { - description: t("store.toast.currenciesUpdated"), - dismissLabel: t("actions.close"), - }) - handleSuccess() - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("store.toast.currenciesUpdated")) + handleSuccess() + }, + onError: (error) => { + toast.error(error.message) + }, + } + ) }) if (isError) { diff --git a/packages/admin-next/dashboard/src/routes/store/store-detail/components/store-currency-section/store-currencies-section.tsx/store-currency-section.tsx b/packages/admin-next/dashboard/src/routes/store/store-detail/components/store-currency-section/store-currencies-section.tsx/store-currency-section.tsx index 2f1b3e3814..fbec5a1915 100644 --- a/packages/admin-next/dashboard/src/routes/store/store-detail/components/store-currency-section/store-currencies-section.tsx/store-currency-section.tsx +++ b/packages/admin-next/dashboard/src/routes/store/store-detail/components/store-currency-section/store-currencies-section.tsx/store-currency-section.tsx @@ -85,25 +85,23 @@ export const StoreCurrencySection = ({ store }: StoreCurrencySectionProps) => { return } - try { - await mutateAsync({ + await mutateAsync( + { supported_currencies: store.supported_currencies?.filter( (c) => !ids.includes(c.currency_code) ) ?? [], - }) - setRowSelection({}) - - toast.success(t("general.success"), { - description: t("store.toast.currenciesRemoved"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + setRowSelection({}) + toast.success(t("store.toast.currenciesRemoved")) + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) } if (isError) { @@ -190,23 +188,21 @@ const CurrencyActions = ({ return } - try { - await mutateAsync({ + await mutateAsync( + { supported_currencies: supportedCurrencies.filter( (c) => c.currency_code !== currency.code ), - }) - - toast.success(t("general.success"), { - description: t("store.toast.currenciesRemoved"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) - } + }, + { + onSuccess: () => { + toast.success(t("store.toast.currenciesRemoved")) + }, + onError: (e) => { + toast.error(e.message) + }, + } + ) } return ( diff --git a/packages/admin-next/dashboard/src/routes/store/store-edit/components/edit-store-form/edit-store-form.tsx b/packages/admin-next/dashboard/src/routes/store/store-edit/components/edit-store-form/edit-store-form.tsx index f3098507dd..d47ccc489e 100644 --- a/packages/admin-next/dashboard/src/routes/store/store-edit/components/edit-store-form/edit-store-form.tsx +++ b/packages/admin-next/dashboard/src/routes/store/store-edit/components/edit-store-form/edit-store-form.tsx @@ -5,10 +5,7 @@ import { useTranslation } from "react-i18next" import { z } from "zod" import { Form } from "../../../../../components/common/form" -import { - RouteDrawer, - useRouteModal, -} from "../../../../../components/modals" +import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useRegions } from "../../../../../hooks/api/regions" import { useUpdateStore } from "../../../../../hooks/api/store" import { ExtendedStoreDTO } from "../../../../../types/api-responses" @@ -44,29 +41,23 @@ export const EditStoreForm = ({ store }: EditStoreFormProps) => { const { regions, isPending: isRegionsLoading } = useRegions({ limit: 999 }) const handleSubmit = form.handleSubmit(async (values) => { - try { - const normalizedMutation = { - ...values, - default_currency_code: undefined, - supported_currencies: store.supported_currencies?.map((c) => ({ - ...c, - is_default: c.currency_code === values.default_currency_code, - })), - } - await mutateAsync(normalizedMutation) - - handleSuccess() - - toast.success(t("general.success"), { - description: t("store.toast.update"), - dismissLabel: t("actions.close"), - }) - } catch (e) { - toast.error(t("general.error"), { - description: e.message, - dismissLabel: t("actions.close"), - }) + const normalizedMutation = { + ...values, + default_currency_code: undefined, + supported_currencies: store.supported_currencies?.map((c) => ({ + ...c, + is_default: c.currency_code === values.default_currency_code, + })), } + await mutateAsync(normalizedMutation, { + onSuccess: () => { + toast.success(t("store.toast.update")) + handleSuccess() + }, + onError: (error) => { + toast.error(error.message) + }, + }) }) return ( diff --git a/packages/design-system/ui/package.json b/packages/design-system/ui/package.json index b97e13c71e..6b0ac8613a 100644 --- a/packages/design-system/ui/package.json +++ b/packages/design-system/ui/package.json @@ -105,7 +105,7 @@ "react-aria": "^3.33.1", "react-currency-input-field": "^3.6.11", "react-stately": "^3.31.1", - "sonner": "^1.4.41", + "sonner": "^1.5.0", "tailwind-merge": "^2.2.1", "upgrade": "^1.1.0", "yarn": "^1.22.22" diff --git a/packages/design-system/ui/src/components/toast/toast.stories.tsx b/packages/design-system/ui/src/components/toast/toast.stories.tsx index 1980b1fe51..c914516fdf 100644 --- a/packages/design-system/ui/src/components/toast/toast.stories.tsx +++ b/packages/design-system/ui/src/components/toast/toast.stories.tsx @@ -1,6 +1,8 @@ import type { Meta, StoryObj } from "@storybook/react" import * as React from "react" +import { Keyboard } from "@medusajs/icons" +import { Kbd } from "../kbd" import { Toast } from "./toast" const meta: Meta = { @@ -58,6 +60,13 @@ export const Loading: Story = { }, } +export const Message: Story = { + args: { + title: Next time hit G then O to go to orders., + icon: , + } +} + export const WithAction: Story = { args: { title: "Scheduled meeting", @@ -70,3 +79,10 @@ export const WithAction: Story = { }, }, } + +export const NoDescription: Story = { + args: { + title: "Label", + variant: "info", + }, +} \ No newline at end of file diff --git a/packages/design-system/ui/src/components/toast/toast.tsx b/packages/design-system/ui/src/components/toast/toast.tsx index b85edd3c08..202ca47192 100644 --- a/packages/design-system/ui/src/components/toast/toast.tsx +++ b/packages/design-system/ui/src/components/toast/toast.tsx @@ -1,17 +1,26 @@ -import { CheckCircleSolid, ExclamationCircleSolid, InformationCircleSolid, Spinner, XCircleSolid } from "@medusajs/icons" +import { + CheckCircleSolid, + ExclamationCircleSolid, + InformationCircleSolid, + Spinner, + XCircleSolid, + XMark, +} from "@medusajs/icons" import * as React from "react" import type { ToastAction, ToastVariant } from "@/types" import { clx } from "@/utils/clx" +import { toast } from "sonner" +import { IconButton } from "../icon-button" interface ToastComponentProps { id: string | number variant?: ToastVariant - title: string - description?: string + title: React.ReactNode + description?: React.ReactNode action?: ToastAction - onDismiss?: (id?: string | number) => void - dismissLabel?: string + icon?: React.ReactNode + dismissable?: boolean } /** @@ -24,7 +33,7 @@ export const Toast = ({ id, /** * @ignore - * + * * @privateRemarks * As the Toast component is created using * the `toast` utility functions, the variant is inferred @@ -33,11 +42,18 @@ export const Toast = ({ variant = "info", /** * @ignore - * + * * @privateRemarks * The `toast` utility functions accept this as a parameter. */ title, + /** + * @ignore + * + * @privateRemarks + * The `toast` utility functions accept this as a parameter. + */ + icon: _icon, /** * The toast's text. */ @@ -48,48 +64,43 @@ export const Toast = ({ action, /** * @ignore - * + * * @privateRemarks - * The `toast` utility functions don't allow - * passing this prop. + * The `toast` utility functions accept this as a parameter. */ - onDismiss, - /** - * The label of the dismiss button, if available. - */ - dismissLabel = "Close", + dismissable = true, }: ToastComponentProps) => { - const hasActionables = !!action || onDismiss - let icon = undefined + let icon = _icon - switch (variant) { - case "success": - icon = - break - case "warning": - icon = - break - case "error": - icon = - break - case "loading": - icon = - break - case "info": - icon = - break - default: - break + if (!_icon) { + switch (variant) { + case "success": + icon = + break + case "warning": + icon = + break + case "error": + icon = + break + case "loading": + icon = + break + case "info": + icon = + break + default: + break + } } return ( -
+
{!!icon && ( @@ -97,29 +108,26 @@ export const Toast = ({ {icon} )} -
- - {title} - - - {description} - -
-
- {hasActionables && ( -
+
+
+ + {title} + + {description && ( + + {description} + + )} +
{!!action && ( - )}
+
+ {!!dismissable && ( + toast.dismiss(id)} + > + + )}
) -} \ No newline at end of file +} diff --git a/packages/design-system/ui/src/utils/toast.tsx b/packages/design-system/ui/src/utils/toast.tsx index 8b4b3b4fb3..d7e55c4b22 100644 --- a/packages/design-system/ui/src/utils/toast.tsx +++ b/packages/design-system/ui/src/utils/toast.tsx @@ -1,44 +1,45 @@ import { Toast } from "@/components/toast" import { ToastAction, ToastVariant, ToasterPosition } from "@/types" import * as React from "react" -import { toast as toastFn } from "sonner" +import { ExternalToast, toast as toastFn } from "sonner" interface BaseToastProps { id?: string | number position?: ToasterPosition - dismissable?: boolean - dismissLabel?: string duration?: number + dismissable?: boolean + icon?: React.ReactNode } interface ToastProps extends BaseToastProps { - description?: string + description?: React.ReactNode action?: ToastAction } -function create(variant: ToastVariant, title: string, props: ToastProps = {}) { - return toastFn.custom( - (t) => { - return ( - toastFn.dismiss(props.id || t) : undefined - } - dismissLabel={props.dismissLabel} - variant={variant} - action={props.action} - /> - ) - }, - { - id: props.id, - position: props.position, - dismissible: props.dismissable, - } - ) +function create(variant: ToastVariant, title: React.ReactNode, props: ToastProps = {}) { + const external: ExternalToast = { + position: props.position, + duration: props.duration, + dismissible: props.dismissable, + } + + if (props.id) { + external.id = props.id + } + + return toastFn.custom((t) => { + return ( + + ) + }, external) } function message( @@ -54,6 +55,12 @@ function message( return create("message", title, props) } +function custom() { + return create("message", "Custom",) +} + +interface VariantToastProps extends Omit {} + function info( /** * The title of the toast. @@ -61,7 +68,7 @@ function info( /** * The props of the toast. */ - props: ToastProps = {} + props: VariantToastProps = {} ) { return create("info", title, props) } @@ -73,7 +80,7 @@ function error( /** * The props of the toast. */ - props: ToastProps = {} + props: VariantToastProps = {} ) { return create("error", title, props) } @@ -85,7 +92,7 @@ function success( /** * The props of the toast. */ - props: ToastProps = {} + props: VariantToastProps = { } ) { return create("success", title, props) } @@ -97,22 +104,19 @@ function warning( /** * The props of the toast. */ - props: ToastProps = {} + props: VariantToastProps = {} ) { return create("warning", title, props) } -type LoadingToastProps = Omit - -function loading -/** - * The title of the toast. - */( - title: string, +function loading( + /** + * The title of the toast. + */ title: string, /** * The props of the toast. */ - props: ToastProps = {} + props: VariantToastProps = {} ) { return create("loading", title, { ...props, dismissable: false }) } @@ -124,7 +128,7 @@ type PromiseStateProps = description?: string } -interface PromiseToastProps extends BaseToastProps { +interface PromiseToastProps extends Omit { loading: PromiseStateProps success: PromiseStateProps error: PromiseStateProps @@ -158,6 +162,7 @@ async function promise( ? undefined : props.loading.description, duration: Infinity, + dismissable: false, } ) diff --git a/yarn.lock b/yarn.lock index 3659ba4240..149cd3cb31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5272,7 +5272,7 @@ __metadata: react-stately: ^3.31.1 resize-observer-polyfill: ^1.5.1 rimraf: ^5.0.1 - sonner: ^1.4.41 + sonner: ^1.5.0 storybook: ^7.0.23 tailwind-merge: ^2.2.1 tailwindcss: ^3.4.3 @@ -27976,13 +27976,13 @@ __metadata: languageName: node linkType: hard -"sonner@npm:^1.4.41": - version: 1.4.41 - resolution: "sonner@npm:1.4.41" +"sonner@npm:^1.5.0": + version: 1.5.0 + resolution: "sonner@npm:1.5.0" peerDependencies: react: ^18.0.0 react-dom: ^18.0.0 - checksum: 31467ecab0fcbd5161fb76d158c698841b524686f7f598eecbc2a58d76bc496b5d5242df4350e274575aa3df59428d3aacd534415c968b19fc309c192c443330 + checksum: 9561b5861bede7f874cc442e447a68c8bfa6e4eadad603bc04e38db35a8b8108741f595a12c9856742062bae230ffedf73122015940491f482c5aa9e68ee85e0 languageName: node linkType: hard