Skip to content

Commit fcf2c79

Browse files
authored
chore(dashboard): fix type and lint errors (4/n) (#15212)
> This PR is part of a series of PRs to fix type and lint issues in the dashboard package. The last PR will enable the type checking as part of the build and add a changeset 1-liner type fixes for the campaign, categories, and customer routes
1 parent 021a9d3 commit fcf2c79

11 files changed

Lines changed: 40 additions & 29 deletions

File tree

packages/admin/dashboard/src/routes/campaigns/campaign-budget-edit/components/edit-campaign-budget-form/edit-campaign-budget-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const EditCampaignBudgetForm = ({
9595
key="usage"
9696
min={0}
9797
{...field}
98-
value={value}
98+
value={value ?? undefined}
9999
onChange={(e) => {
100100
onChange(
101101
e.target.value === ""

packages/admin/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export const CreateCampaignSchema = zod.object({
2323
budget: zod.object({
2424
attribute: zod.string().nullish(),
2525
limit: zod.number().min(0).nullish(),
26-
type: zod.enum(["spend", "usage", "use_by_attribute"]),
26+
type: zod.enum([
27+
"spend",
28+
"usage",
29+
"use_by_attribute",
30+
"spend_by_attribute",
31+
]),
2732
currency_code: zod.string().nullish(),
2833
}),
2934
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./campaign-configuration-section";
1+
export * from "./campaign-configuration-section"

packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-spend/campaign-spend.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const CampaignSpend = ({ campaign }: CampaignSpendProps) => {
2323
{campaign.budget?.type === "use_by_attribute"
2424
? t("campaigns.fields.totalUsedByAttribute")
2525
: campaign.budget?.type === "spend"
26-
? t("campaigns.fields.total_spend")
27-
: t("campaigns.fields.total_used")}
26+
? t("campaigns.fields.total_spend")
27+
: t("campaigns.fields.total_used")}
2828
</Heading>
2929
</div>
3030

packages/admin/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import {
2121
} from "../../../../../lib/data/currencies"
2222
import { Combobox } from "../../../../../components/inputs/combobox"
2323

24-
export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
24+
export const CreateCampaignFormFields = ({
25+
form,
26+
fieldScope = "",
27+
}: {
28+
form: any
29+
fieldScope?: string
30+
}) => {
2531
const { t } = useTranslation()
2632
const { store } = useStore()
2733
const direction = useDocumentDirection()

packages/admin/dashboard/src/routes/categories/categories-metadata/categories-metadata.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import { RouteDrawer } from "../../../components/modals"
1010
export const CategoriesMetadata = () => {
1111
const { id } = useParams()
1212

13-
const { product_category, isPending, isError, error } = useProductCategory(id)
14-
const { mutateAsync, isPending: isMutating } = useUpdateProductCategory(id)
13+
const { product_category, isPending, isError, error } = useProductCategory(
14+
id ?? ""
15+
)
16+
const { mutateAsync, isPending: isMutating } = useUpdateProductCategory(
17+
id ?? ""
18+
)
1519

1620
if (isError) {
1721
throw error

packages/admin/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-details.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ export const CreateCategoryDetails = ({ form }: CreateCategoryDetailsProps) => {
8181
<Form.Item>
8282
<Form.Label>{t("categories.fields.status.label")}</Form.Label>
8383
<Form.Control>
84-
<Select
85-
dir={direction}
86-
{...field}
87-
onValueChange={onChange}
88-
>
84+
<Select dir={direction} {...field} onValueChange={onChange}>
8985
<Select.Trigger ref={ref}>
9086
<Select.Value />
9187
</Select.Trigger>
@@ -114,11 +110,7 @@ export const CreateCategoryDetails = ({ form }: CreateCategoryDetailsProps) => {
114110
{t("categories.fields.visibility.label")}
115111
</Form.Label>
116112
<Form.Control>
117-
<Select
118-
dir={direction}
119-
{...field}
120-
onValueChange={onChange}
121-
>
113+
<Select dir={direction} {...field} onValueChange={onChange}>
122114
<Select.Trigger ref={ref}>
123115
<Select.Value />
124116
</Select.Trigger>

packages/admin/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export const CreateCategoryForm = ({
6161
})
6262

6363
if (!result.success) {
64-
result.error.errors.forEach((error) => {
65-
form.setError(error.path.join(".") as keyof CreateCategorySchema, {
64+
result.error.issues.forEach(({ path, message }) => {
65+
form.setError(path.join(".") as keyof CreateCategorySchema, {
6666
type: "manual",
67-
message: error.message,
67+
message,
6868
})
6969
})
7070

@@ -130,8 +130,9 @@ export const CreateCategoryForm = ({
130130
onSubmit={handleSubmit}
131131
className="flex size-full flex-col overflow-hidden"
132132
>
133-
<ProgressTabs
134-
dir={direction}value={activeTab}
133+
<ProgressTabs
134+
dir={direction}
135+
value={activeTab}
135136
onValueChange={(tab) => handleTabChange(tab as Tab)}
136137
className="flex size-full flex-col"
137138
>

packages/admin/dashboard/src/routes/customers/customer-detail/components/customer-order-section/customer-order-section.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type CustomerGeneralSectionProps = {
1919

2020
const PREFIX = "cusord"
2121
const PAGE_SIZE = 10
22-
const DEFAULT_RELATIONS = "*customer,*items,*sales_channel,*payment_collections,+shipping_address.country_code"
22+
const DEFAULT_RELATIONS =
23+
"*customer,*items,*sales_channel,*payment_collections,+shipping_address.country_code"
2324
const DEFAULT_FIELDS =
2425
"id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code"
2526

@@ -63,12 +64,12 @@ export const CustomerOrderSection = ({
6364
<Container className="divide-y p-0">
6465
<div className="flex items-center justify-between px-6 py-4">
6566
<Heading level="h2">{t("orders.domain")}</Heading>
66-
{/*TODO: ENABLE WHEN DRAFT ORDERS ARE DONE*/}
67-
{/*<div className="flex items-center gap-x-2">*/}
67+
{/* TODO: ENABLE WHEN DRAFT ORDERS ARE DONE*/}
68+
{/* <div className="flex items-center gap-x-2">*/}
6869
{/* <Button size="small" variant="secondary">*/}
6970
{/* {t("actions.create")}*/}
7071
{/* </Button>*/}
71-
{/*</div>*/}
72+
{/* </div>*/}
7273
</div>
7374
<_DataTable
7475
columns={columns}

packages/admin/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ export const AddCustomerGroupsForm = ({
129129

130130
handleSuccess(`/customers/${customerId}`)
131131
} catch (e) {
132-
toast.error(e.message)
132+
toast.error(
133+
e instanceof Error ? e.message : t("errorBoundary.defaultTitle")
134+
)
133135
} finally {
134136
setIsPending(false)
135137
}

0 commit comments

Comments
 (0)