saleor-dashboard/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.tsx
Tomasz Szymański c30429f7f4
Implement inclusion feature of postal codes (#983)
* Temporary merged schema and types update

* Update typing for zipCodeRules -> postalCodeRules

* Refactor zipCodes to postalCodes

* Fix new schema webhooks

* Delete postal code unassign dialog

* Query inclusion type from backend

* Clean up schema from old mutations

* Proper new mutations structure, all postal code related changes

* Linter changes

* Fix bug with save not being refreshed after codes are added / deleted / inclusion change

* Tests and translations

* Fix warnings across app, minor variables refactor

* Linting

* Trigger deployment

* CR changes, cleanups and refactors

* Update snapshots

* Resolve bug with radio not shows correct value on page refresh

* Fix price and weight creation of codes

* Reducer

* Revert "Reducer"

This reverts commit 07a3aed9c88332bde7d9be61b6dbc29e34e4edba.
2021-02-23 09:58:25 +01:00

117 lines
3.6 KiB
TypeScript

import Typography from "@material-ui/core/Typography";
import ActionDialog from "@saleor/components/ActionDialog";
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
import {
Choices,
SingleSelectField
} from "@saleor/components/SingleSelectField";
import useStateFromProps from "@saleor/hooks/useStateFromProps";
import { buttonMessages } from "@saleor/intl";
import React from "react";
import { defineMessages, useIntl } from "react-intl";
import { useStyles } from "../styles";
const messages = defineMessages({
deleteChannel: {
defaultMessage: "Delete Channel",
description: "dialog header"
},
deletingAllProductData: {
defaultMessage:
"Deleting channel will delete all product data regarding this channel. Are you sure you want to delete this channel?",
description: "delete channel"
},
needToBeMoved: {
defaultMessage:
"All order information from this channel need to be moved to a different channel. Please select channel orders need to be moved to:.",
description: "delete channel"
},
noAvailableChannel: {
defaultMessage:
"There is no available channel to move order information to. Please create a channel with same currency so that information can be moved to it.",
description: "currency channel"
},
selectChannel: {
defaultMessage: "Select Channel",
description: "dialog header"
}
});
export interface ChannelDeleteDialogProps {
channelsChoices: Choices;
hasOrders: boolean;
confirmButtonState: ConfirmButtonTransitionState;
open: boolean;
onBack: () => void;
onClose: () => void;
onConfirm: (targetChannelId: string) => void;
}
const ChannelDeleteDialog: React.FC<ChannelDeleteDialogProps> = ({
channelsChoices = [],
hasOrders,
confirmButtonState,
open,
onBack,
onClose,
onConfirm
}) => {
const classes = useStyles({});
const intl = useIntl();
const [choice, setChoice] = useStateFromProps(
!!channelsChoices.length ? channelsChoices[0].value : ""
);
const hasChannels = !!channelsChoices?.length;
const canBeDeleted = hasChannels || !hasOrders;
return (
<ActionDialog
confirmButtonState={confirmButtonState}
open={open}
onClose={onClose}
onConfirm={() => (canBeDeleted ? onConfirm(choice) : onBack())}
title={intl.formatMessage(messages.deleteChannel)}
confirmButtonLabel={intl.formatMessage(
canBeDeleted ? buttonMessages.delete : buttonMessages.ok
)}
variant={canBeDeleted ? "delete" : "default"}
>
<div>
{hasOrders ? (
hasChannels ? (
<>
<Typography>
{intl.formatMessage(messages.needToBeMoved)}
</Typography>
<div className={classes.select}>
<SingleSelectField
choices={channelsChoices}
name="channels"
label={intl.formatMessage(messages.selectChannel)}
value={choice}
onChange={e => setChoice(e.target.value)}
/>
</div>
<Typography>
{intl.formatMessage(messages.deletingAllProductData)}
</Typography>
</>
) : (
<Typography>
{intl.formatMessage(messages.noAvailableChannel)}
</Typography>
)
) : (
<Typography>
{intl.formatMessage(messages.deletingAllProductData)}
</Typography>
)}
</div>
</ActionDialog>
);
};
ChannelDeleteDialog.displayName = "ChannelDeleteDialog";
export default ChannelDeleteDialog;