saleor-dashboard/src/navigation/components/MenuCreateDialog/MenuCreateDialog.tsx

96 lines
2.6 KiB
TypeScript
Raw Normal View History

import BackButton from "@dashboard/components/BackButton";
import {
ConfirmButton,
ConfirmButtonTransitionState,
} from "@dashboard/components/ConfirmButton";
import Form from "@dashboard/components/Form";
import { MenuErrorFragment } from "@dashboard/graphql";
import { buttonMessages } from "@dashboard/intl";
import { getFormErrors } from "@dashboard/utils/errors";
import getMenuErrorMessage from "@dashboard/utils/errors/menu";
import {
Dialog,
DialogActions,
DialogContent,
DialogTitle,
TextField,
} from "@material-ui/core";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
export interface MenuCreateDialogFormData {
name: string;
}
export interface MenuCreateDialogProps {
confirmButtonState: ConfirmButtonTransitionState;
disabled: boolean;
2020-03-11 13:03:31 +00:00
errors: MenuErrorFragment[];
2019-06-19 14:40:52 +00:00
open: boolean;
onClose: () => void;
onConfirm: (data: MenuCreateDialogFormData) => void;
}
const initialForm: MenuCreateDialogFormData = {
name: "",
2019-06-19 14:40:52 +00:00
};
const MenuCreateDialog: React.FC<MenuCreateDialogProps> = ({
confirmButtonState,
disabled,
2020-02-24 14:14:48 +00:00
errors,
2019-06-19 14:40:52 +00:00
onClose,
onConfirm,
open,
}) => {
const intl = useIntl();
2020-03-11 13:03:31 +00:00
const formErrors = getFormErrors(["name"], errors);
return (
<Dialog onClose={onClose} maxWidth="sm" fullWidth open={open}>
<DialogTitle disableTypography>
<FormattedMessage
id="0OtaXa"
2019-09-05 13:33:50 +00:00
defaultMessage="Create Menu"
description="dialog header"
/>
</DialogTitle>
<Form initial={initialForm} onSubmit={onConfirm}>
2020-02-24 14:14:48 +00:00
{({ change, data, submit }) => (
<>
<DialogContent>
<TextField
disabled={disabled}
2020-03-11 13:03:31 +00:00
error={!!formErrors.name}
fullWidth
2020-03-11 13:03:31 +00:00
helperText={getMenuErrorMessage(formErrors.name, intl)}
label={intl.formatMessage({
id: "jhh/D6",
defaultMessage: "Menu Title",
})}
name={"name" as keyof MenuCreateDialogFormData}
value={data.name}
onChange={change}
/>
</DialogContent>
<DialogActions>
Bump macaw to 0.3 (#1807) * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 12:34:20 +00:00
<BackButton onClick={onClose} />
<ConfirmButton
transitionState={confirmButtonState}
onClick={submit}
data-test-id="submit"
>
<FormattedMessage {...buttonMessages.save} />
</ConfirmButton>
</DialogActions>
</>
)}
</Form>
</Dialog>
);
};
2019-06-19 14:40:52 +00:00
MenuCreateDialog.displayName = "MenuCreateDialog";
export default MenuCreateDialog;