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.
This commit is contained in:
Kasper Fabricius Kristensen
2024-07-09 16:14:19 +00:00
committed by GitHub
parent 24fc6befd2
commit 6e613f4f50
88 changed files with 811 additions and 1182 deletions
@@ -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": {
@@ -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 = () => {
@@ -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)
},
})
}
@@ -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)
},
}
)
@@ -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)
},
})
})
@@ -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 (
@@ -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)
},
}
)
@@ -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),
}
)
})
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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)
},
}
)
@@ -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 (
@@ -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)
},
}
@@ -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)
},
}
)
@@ -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 (
<RouteDrawer>
<RouteDrawer.Header>
<Heading>Edit</Heading>
<RouteDrawer.Title asChild>
<Heading>{t("categories.edit.header")}</Heading>
</RouteDrawer.Title>
<RouteDrawer.Description className="sr-only">
{t("categories.edit.description")}
</RouteDrawer.Description>
</RouteDrawer.Header>
{ready && <EditCategoryForm category={product_category} />}
</RouteDrawer>
@@ -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<z.infer<typeof EditCategorySchema>>({
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 (
<RouteDrawer.Form form={form}>
@@ -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({
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
}
)
})
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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)
},
})
})
@@ -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)
},
})
}
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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"),
}}
/>
</Container>
@@ -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 (
@@ -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)
},
}
)
@@ -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)
}
@@ -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) {
/>
</div>
{/*<Form.Field*/}
{/* <Form.Field*/}
{/* className="col-span-1"*/}
{/* control={form.control}*/}
{/* name="location_ids"*/}
@@ -370,7 +364,7 @@ export function CreateInventoryItemForm({}: CreateInventoryItemFormProps) {
{/* </Form.Item>*/}
{/* )*/}
{/* }}*/}
{/*/>*/}
{/* />*/}
</div>
<Heading level="h3" className="my-6">
@@ -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 (
@@ -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),
})
})
@@ -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),
})
})
@@ -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 (
@@ -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)
},
})
}
@@ -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"),
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
},
}
)
@@ -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)
}
})
@@ -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<zod.infer<typeof CreateShipmentSchema>>({
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) => (
<Form.Field
key={label.id}
control={form.control}
name={`labels.${index}.tracking_number`}
render={({ field }) => {
@@ -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)
},
})
}
}
@@ -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)
},
})
}
@@ -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)
},
})
}
@@ -31,22 +31,16 @@ export const CreateProductTypeForm = () => {
async (values: z.infer<typeof CreateProductTypeSchema>) => {
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)
},
})
}
@@ -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)
},
}
)
@@ -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)
},
})
})
@@ -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)
},
})
})
@@ -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()
@@ -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"),
})
},
})
@@ -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)
},
}
)
@@ -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)
}
})
@@ -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"))
}
}
)
@@ -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 (
@@ -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)
},
}
)
})
@@ -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 (
@@ -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 (
@@ -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)
},
}
)
})
@@ -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)
},
})
})
@@ -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)
},
})
})
@@ -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),
}
)
})
@@ -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),
}
)
})
@@ -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 (
@@ -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 (
@@ -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)
},
}
)
@@ -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 (
@@ -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)
},
}
)
@@ -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)
},
})
}
@@ -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)
},
})
}
@@ -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) {
@@ -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 (
@@ -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 (