2023-01-16 09:45:12 +00:00
|
|
|
import ActionDialog from "@dashboard/components/ActionDialog";
|
|
|
|
import { getStringOrPlaceholder } from "@dashboard/misc";
|
2023-01-10 10:04:30 +00:00
|
|
|
import { DialogContentText } from "@material-ui/core";
|
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
|
|
|
|
import msgs from "./messages";
|
|
|
|
|
|
|
|
export interface AppDeleteDialogProps {
|
|
|
|
confirmButtonState: ConfirmButtonTransitionState;
|
|
|
|
open: boolean;
|
|
|
|
name?: string | null;
|
|
|
|
onClose: () => void;
|
|
|
|
onConfirm: () => void;
|
|
|
|
type: "CUSTOM" | "EXTERNAL";
|
|
|
|
}
|
|
|
|
|
|
|
|
const AppDeleteDialog: React.FC<AppDeleteDialogProps> = ({
|
|
|
|
confirmButtonState,
|
|
|
|
open,
|
|
|
|
name,
|
|
|
|
onClose,
|
|
|
|
onConfirm,
|
|
|
|
type,
|
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2023-01-19 11:54:57 +00:00
|
|
|
const isNameMissing = name === null || name === "";
|
2023-01-10 10:04:30 +00:00
|
|
|
const isExternal = type === "EXTERNAL";
|
|
|
|
|
|
|
|
const getMainText = () => {
|
2023-01-19 11:54:57 +00:00
|
|
|
if (isNameMissing && isExternal) {
|
2023-01-10 10:04:30 +00:00
|
|
|
return intl.formatMessage(msgs.deleteApp);
|
|
|
|
}
|
2023-01-19 11:54:57 +00:00
|
|
|
if (isNameMissing) {
|
2023-01-10 10:04:30 +00:00
|
|
|
return intl.formatMessage(msgs.deleteLocalApp);
|
|
|
|
}
|
|
|
|
if (isExternal) {
|
|
|
|
return intl.formatMessage(msgs.deleteNamedApp, {
|
|
|
|
name: <strong>{getStringOrPlaceholder(name)}</strong>,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return intl.formatMessage(msgs.deleteLocalNamedApp, {
|
|
|
|
name: <strong>{getStringOrPlaceholder(name)}</strong>,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ActionDialog
|
|
|
|
confirmButtonState={confirmButtonState}
|
|
|
|
open={open}
|
|
|
|
onClose={onClose}
|
|
|
|
onConfirm={onConfirm}
|
|
|
|
title={intl.formatMessage(msgs.deleteAppTitle)}
|
|
|
|
variant="delete"
|
|
|
|
>
|
|
|
|
<DialogContentText data-test-id="dialog-content">
|
|
|
|
{getMainText()} <FormattedMessage {...msgs.deleteAppQuestion} />
|
|
|
|
</DialogContentText>
|
|
|
|
</ActionDialog>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
AppDeleteDialog.displayName = "AppDeleteDialog";
|
|
|
|
export default AppDeleteDialog;
|