import { TextField, Typography } from "@material-ui/core"; import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer"; import VerticalSpacer from "@saleor/apps/components/VerticalSpacer"; import ControlledCheckbox from "@saleor/components/ControlledCheckbox"; import RadioGroupField from "@saleor/components/RadioGroupField"; import TimePeriodField from "@saleor/giftCards/components/TimePeriodField"; import { GiftCardBulkCreateFormErrors, GiftCardCreateCommonFormData } from "@saleor/giftCards/GiftCardBulkCreateDialog/types"; import { GiftCardExpiryType } from "@saleor/giftCards/GiftCardCreateDialog/types"; import { getExpiryPeriodTerminationDate } from "@saleor/giftCards/GiftCardCreateDialog/utils"; import { getGiftCardErrorMessage } from "@saleor/giftCards/GiftCardUpdate/messages"; import useCurrentDate from "@saleor/hooks/useCurrentDate"; import { FormChange } from "@saleor/hooks/useForm"; import React from "react"; import { FormattedMessage } from "react-intl"; import { MessageDescriptor, useIntl } from "react-intl"; import { giftCardCreateExpirySelectMessages as messages } from "./messages"; import { useGiftCardCreateExpirySelectStyles as useStyles } from "./styles"; interface UntranslatedOption { label: MessageDescriptor; value: GiftCardExpiryType; } const options: UntranslatedOption[] = [ { label: messages.expiryPeriodLabel, value: "EXPIRY_PERIOD" }, { label: messages.expiryDateLabel, value: "EXPIRY_DATE" } ]; interface GiftCardCreateExpirySelectProps { errors: GiftCardBulkCreateFormErrors; change: FormChange; data: Pick< GiftCardCreateCommonFormData, | "expirySelected" | "expiryPeriodType" | "expiryPeriodAmount" | "expiryType" | "expiryDate" >; } const GiftCardCreateExpirySelect: React.FC = ({ errors, change, data: { expirySelected, expiryPeriodType, expiryPeriodAmount, expiryType, expiryDate } }) => { const intl = useIntl(); const classes = useStyles({}); const translatedOptions = options.map(({ label, value }) => ({ value, label: intl.formatMessage(label) })); const currentDate = useCurrentDate(); return ( <> {expirySelected && ( <> {expiryType === "EXPIRY_DATE" && ( )} {expiryType === "EXPIRY_PERIOD" && (
{getExpiryPeriodTerminationDate( currentDate, expiryPeriodType, expiryPeriodAmount )?.format("L")}
)} )} ); }; export default GiftCardCreateExpirySelect;