saleor-dashboard/src/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx
Dominik Żegleń f8254fd11b
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 13:34:20 +01:00

156 lines
4.9 KiB
TypeScript

import {
Dialog,
DialogActions,
DialogContent,
DialogTitle,
TextField
} from "@material-ui/core";
import BackButton from "@saleor/components/BackButton";
import ConfirmButton from "@saleor/components/ConfirmButton";
import Form from "@saleor/components/Form";
import FormSpacer from "@saleor/components/FormSpacer";
import { StaffErrorFragment } from "@saleor/fragments/types/StaffErrorFragment";
import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
import { commonMessages } from "@saleor/intl";
import { ConfirmButtonTransitionState, makeStyles } from "@saleor/macaw-ui";
import { SearchPermissionGroups_search_edges_node } from "@saleor/searches/types/SearchPermissionGroups";
import { FetchMoreProps, SearchPageProps } from "@saleor/types";
import { getFormErrors } from "@saleor/utils/errors";
import getStaffErrorMessage from "@saleor/utils/errors/staff";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
export interface AddMemberFormData {
email: string;
firstName: string;
lastName: string;
permissionGroups: string[];
}
const initialForm: AddMemberFormData = {
email: "",
firstName: "",
lastName: "",
permissionGroups: []
};
const useStyles = makeStyles(
theme => ({
hr: {
backgroundColor: "#eaeaea",
border: "none",
height: 1,
marginBottom: 0
},
sectionTitle: {
fontWeight: 600 as 600,
marginBottom: theme.spacing(),
marginTop: theme.spacing(2)
},
textFieldGrid: {
display: "grid",
gridColumnGap: theme.spacing(2),
gridTemplateColumns: "1fr 1fr"
}
}),
{ name: "StaffAddMemberDialog" }
);
interface StaffAddMemberDialogProps extends SearchPageProps {
availablePermissionGroups: SearchPermissionGroups_search_edges_node[];
confirmButtonState: ConfirmButtonTransitionState;
disabled: boolean;
errors: StaffErrorFragment[];
fetchMorePermissionGroups: FetchMoreProps;
open: boolean;
onClose: () => void;
onConfirm: (data: AddMemberFormData) => void;
}
const StaffAddMemberDialog: React.FC<StaffAddMemberDialogProps> = props => {
const { confirmButtonState, errors, onClose, onConfirm, open } = props;
const classes = useStyles(props);
const dialogErrors = useModalDialogErrors(errors, open);
const intl = useIntl();
const formErrors = getFormErrors(
["firstName", "lastName", "email"],
dialogErrors
);
return (
<Dialog onClose={onClose} open={open}>
<Form initial={initialForm} onSubmit={onConfirm}>
{({ change, data: formData, hasChanged }) => (
<>
<DialogTitle>
<FormattedMessage
defaultMessage="Invite Staff Member"
description="dialog header"
/>
</DialogTitle>
<DialogContent>
<div className={classes.textFieldGrid}>
<TextField
error={!!formErrors.firstName}
helperText={
!!formErrors.firstName &&
getStaffErrorMessage(formErrors.firstName, intl)
}
label={intl.formatMessage(commonMessages.firstName)}
name="firstName"
type="text"
value={formData.firstName}
onChange={change}
/>
<TextField
error={!!formErrors.lastName}
helperText={
!!formErrors.lastName &&
getStaffErrorMessage(formErrors.lastName, intl)
}
label={intl.formatMessage(commonMessages.lastName)}
name="lastName"
type="text"
value={formData.lastName}
onChange={change}
/>
</div>
<FormSpacer />
<TextField
error={!!formErrors.email}
fullWidth
helperText={
!!formErrors.email &&
getStaffErrorMessage(formErrors.email, intl)
}
label={intl.formatMessage(commonMessages.email)}
name="email"
type="email"
value={formData.email}
onChange={change}
/>
</DialogContent>
<hr className={classes.hr} />
<DialogActions>
<BackButton onClick={onClose} />
<ConfirmButton
data-test="submit"
disabled={!hasChanged}
type="submit"
transitionState={confirmButtonState}
>
<FormattedMessage
defaultMessage="Send invite"
description="button"
/>
</ConfirmButton>
</DialogActions>
</>
)}
</Form>
</Dialog>
);
};
StaffAddMemberDialog.displayName = "StaffAddMemberDialog";
export default StaffAddMemberDialog;