-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for discount type (#4641)
* Refactor rule model * Add changeset * Add discount type component * Add type to initial form values * Bump macaw * Refactor Add button * Update test * Refactor DiscountRule isLoaded * Add type support * Remve useeffect * Add changeset * Extract messages * Fix typo
- Loading branch information
Showing
20 changed files
with
167 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": minor | ||
--- | ||
|
||
Add discount type to form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/discounts/components/DiscountGeneralInfo/DiscountGeneralInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { DashboardCard } from "@dashboard/components/Card"; | ||
import { DiscoutFormData } from "@dashboard/discounts/types"; | ||
import { Box, Input, Select } from "@saleor/macaw-ui-next"; | ||
import React, { useMemo } from "react"; | ||
import { useController, useFormContext } from "react-hook-form"; | ||
import { FormattedMessage, useIntl } from "react-intl"; | ||
|
||
interface DiscountNameProps { | ||
disabled?: boolean; | ||
typeDisabled?: boolean; | ||
error: string | undefined; | ||
} | ||
|
||
export const DiscountGeneralInfo = ({ | ||
disabled, | ||
typeDisabled, | ||
error, | ||
}: DiscountNameProps) => { | ||
const intl = useIntl(); | ||
const { formState } = useFormContext<DiscoutFormData>(); | ||
const { field: nameField } = useController<DiscoutFormData, "name">({ | ||
name: "name", | ||
}); | ||
const { field: typeField } = useController<DiscoutFormData, "type">({ | ||
name: "type", | ||
}); | ||
|
||
const discountTypes = useMemo( | ||
() => [ | ||
{ | ||
label: intl.formatMessage({ | ||
defaultMessage: "Catalog", | ||
id: "0khVBN", | ||
description: "discount type", | ||
}), | ||
value: "catalog", | ||
}, | ||
// Uncomment when API will support catalog discounts | ||
// { | ||
// label: intl.formatMessage({ | ||
// defaultMessage: "Order", | ||
// id: "onUvP+", | ||
// description: "discount type", | ||
// }), | ||
// value: "order", | ||
// }, | ||
], | ||
[intl], | ||
); | ||
|
||
return ( | ||
<DashboardCard> | ||
<DashboardCard.Title> | ||
<FormattedMessage defaultMessage="General information" id="fKrRhF" /> | ||
</DashboardCard.Title> | ||
<DashboardCard.Content> | ||
<Box display="grid" gap={3}> | ||
<Input | ||
{...nameField} | ||
error={!!error || !!formState.errors?.name} | ||
helperText={error || formState.errors?.name?.message} | ||
label={intl.formatMessage({ | ||
defaultMessage: "Discount name", | ||
id: "lJXkFS", | ||
description: "discount name", | ||
})} | ||
disabled={disabled || nameField.disabled} | ||
/> | ||
|
||
<Box __width={250}> | ||
<Select | ||
{...typeField} | ||
size="medium" | ||
options={discountTypes} | ||
label={intl.formatMessage({ | ||
defaultMessage: "Discount type", | ||
id: "z/2AZY", | ||
})} | ||
disabled={typeDisabled || nameField.disabled} | ||
/> | ||
</Box> | ||
</Box> | ||
</DashboardCard.Content> | ||
</DashboardCard> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./DiscountGeneralInfo"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.