diff --git a/packages/admin-next/dashboard/src/i18n/translations/en.json b/packages/admin-next/dashboard/src/i18n/translations/en.json index 3588473099..c2bc18066b 100644 --- a/packages/admin-next/dashboard/src/i18n/translations/en.json +++ b/packages/admin-next/dashboard/src/i18n/translations/en.json @@ -1137,7 +1137,11 @@ "campaignType": "Select the currency code in the promotion tab to enable it." }, "errors": { - "requiredField": "Required field" + "requiredField": "Required field", + "promotionTabError": "Fix errors in Promotion Tab before proceeding" + }, + "toasts": { + "promotionCreateSuccess": "Promotion ({{code}}) was successfully created." }, "create": {}, "edit": { 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 18ba0e4824..adf81d25cb 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 @@ -10,6 +10,7 @@ import { ProgressTabs, RadioGroup, Text, + toast, } from "@medusajs/ui" import { useEffect, useMemo, useState } from "react" import { useForm, useWatch } from "react-hook-form" @@ -121,21 +122,48 @@ export const CreatePromotionForm = () => { })) } - createPromotion({ - ...promotionData, - rules: buildRulesData(rules), - application_method: { - ...applicationMethodData, - ...applicationMethodRuleData, - target_rules: buildRulesData(targetRulesData), - buy_rules: buildRulesData(buyRulesData), + createPromotion( + { + ...promotionData, + rules: buildRulesData(rules), + application_method: { + ...applicationMethodData, + ...applicationMethodRuleData, + target_rules: buildRulesData(targetRulesData), + buy_rules: buildRulesData(buyRulesData), + }, + is_automatic: is_automatic === "true", }, - is_automatic: is_automatic === "true", - }).then(() => handleSuccess()) + { + onSuccess: ({ promotion }) => { + toast.success(t("general.success"), { + description: 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"), + }) + }, + } + ) }, async (error) => { - // TODO: showcase error when something goes wrong - // Wait for alert component and use it here + const { campaign, ...rest } = error || {} + const errorInPromotionTab = !!Object.keys(rest || {}).length + + if (errorInPromotionTab) { + toast.error(t("general.error"), { + description: t("promotions.errors.promotionTabError"), + dismissLabel: t("general.close"), + }) + } } )