Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Extract staff view modals outside pages

dominik-zeglen1cb8013b0b10
diff --git a/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx b/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
index d3a74e0045..ae7e57568f 100644
--- a/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
+++ b/saleor/static/dashboard-next/components/ActionDialog/ActionDialog.tsx
@@ -14,7 +14,7 @@ interface ActionDialogProps {
title: string;
variant?: string;
onClose?();
- onConfirm?(event: React.FormEvent<any>);
+ onConfirm();
}
const decorate = withStyles(theme => ({
diff --git a/saleor/static/dashboard-next/staff/components/StaffDetailsPage/StaffDetailsPage.tsx b/saleor/static/dashboard-next/staff/components/StaffDetailsPage/StaffDetailsPage.tsx
index 8242bd540d..32dd608ec2 100644
--- a/saleor/static/dashboard-next/staff/components/StaffDetailsPage/StaffDetailsPage.tsx
+++ b/saleor/static/dashboard-next/staff/components/StaffDetailsPage/StaffDetailsPage.tsx
@@ -1,14 +1,10 @@
-import DialogContentText from "@material-ui/core/DialogContentText";
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
-import ActionDialog from "../../../components/ActionDialog";
import Container from "../../../components/Container";
import Form from "../../../components/Form";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
-import Toggle from "../../../components/Toggle";
-import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import {
StaffMemberDetails_shop_permissions,
@@ -70,70 +66,48 @@ const StaffDetailsPage = decorate<StaffDetailsPageProps>(
)
};
return (
- <Toggle>
- {(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
- <>
- <Form
- initial={initialForm}
- onSubmit={onSubmit}
- key={JSON.stringify({ staffMember, permissions })}
- >
- {({ data, change, submit }) => (
- <Container width="md">
- <PageHeader
- title={maybe(() => staffMember.email)}
- onBack={onBack}
+ <Form
+ initial={initialForm}
+ onSubmit={onSubmit}
+ key={JSON.stringify({ staffMember, permissions })}
+ >
+ {({ data, change, submit }) => (
+ <Container width="md">
+ <PageHeader
+ title={maybe(() => staffMember.email)}
+ onBack={onBack}
+ />
+ <div className={classes.root}>
+ <div>
+ <StaffProperties
+ className={classes.card}
+ staffMember={staffMember}
+ />
+ </div>
+ <div>
+ <div className={classes.card}>
+ <StaffPermissions
+ data={data}
+ disabled={disabled}
+ permissions={permissions}
+ onChange={change}
/>
- <div className={classes.root}>
- <div>
- <StaffProperties
- className={classes.card}
- staffMember={staffMember}
- />
- </div>
- <div>
- <div className={classes.card}>
- <StaffPermissions
- data={data}
- disabled={disabled}
- permissions={permissions}
- onChange={change}
- />
- </div>
- <StaffStatus
- data={data}
- disabled={disabled}
- onChange={change}
- />
- </div>
- </div>
- <SaveButtonBar
- onCancel={onBack}
- onSave={submit}
- onDelete={toggleDeleteDialog}
- />
- </Container>
- )}
- </Form>
- <ActionDialog
- open={openedDeleteDialog}
- title={i18n.t("Remove staff user")}
- variant="delete"
- onClose={toggleDeleteDialog}
- onConfirm={onDelete}
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ email }}</strong> from staff members?",
- { email: maybe(() => staffMember.email) }
- )
- }}
- />
- </ActionDialog>
- </>
+ </div>
+ <StaffStatus
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ </div>
+ </div>
+ <SaveButtonBar
+ onCancel={onBack}
+ onSave={submit}
+ onDelete={onDelete}
+ />
+ </Container>
)}
- </Toggle>
+ </Form>
);
}
);
diff --git a/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx b/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx
index 1e958c2cb8..203b392e96 100644
--- a/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx
+++ b/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx
@@ -4,24 +4,18 @@ import * as React from "react";
import { Container } from "../../../components/Container";
import PageHeader from "../../../components/PageHeader";
-import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
-import { ListProps, UserError } from "../../../types";
+import { ListProps } from "../../../types";
import { StaffList_staffUsers_edges_node } from "../../types/StaffList";
-import StaffAddMemberDialog, {
- FormData as AddStaffMemberForm
-} from "../StaffAddMemberDialog/StaffAddMemberDialog";
import StaffList from "../StaffList/StaffList";
export interface StaffListPageProps extends ListProps {
- errors: UserError[];
staffMembers: StaffList_staffUsers_edges_node[];
- onAdd: (data: AddStaffMemberForm) => void;
+ onAdd: () => void;
}
const StaffListPage: React.StatelessComponent<StaffListPageProps> = ({
disabled,
- errors,
pageInfo,
staffMembers,
onAdd,
@@ -29,37 +23,27 @@ const StaffListPage: React.StatelessComponent<StaffListPageProps> = ({
onPreviousPage,
onRowClick
}) => (
- <Toggle>
- {(openedAddStaffMemberDialog, { toggle: toggleAddStaffMemberDialog }) => (
- <Container width="md">
- <PageHeader title={i18n.t("Staff members", { context: "page title" })}>
- <Button
- color="secondary"
- disabled={disabled}
- variant="contained"
- onClick={toggleAddStaffMemberDialog}
- >
- {i18n.t("Add staff member", { context: "button" })}
- <AddIcon />
- </Button>
- </PageHeader>
- <StaffList
- disabled={disabled}
- pageInfo={pageInfo}
- staffMembers={staffMembers}
- onNextPage={onNextPage}
- onPreviousPage={onPreviousPage}
- onRowClick={onRowClick}
- />
- <StaffAddMemberDialog
- errors={errors}
- open={openedAddStaffMemberDialog}
- onClose={toggleAddStaffMemberDialog}
- onConfirm={onAdd}
- />
- </Container>
- )}
- </Toggle>
+ <Container width="md">
+ <PageHeader title={i18n.t("Staff members", { context: "page title" })}>
+ <Button
+ color="secondary"
+ disabled={disabled}
+ variant="contained"
+ onClick={onAdd}
+ >
+ {i18n.t("Add staff member", { context: "button" })}
+ <AddIcon />
+ </Button>
+ </PageHeader>
+ <StaffList
+ disabled={disabled}
+ pageInfo={pageInfo}
+ staffMembers={staffMembers}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onRowClick}
+ />
+ </Container>
);
StaffListPage.displayName = "StaffListPage";
export default StaffListPage;
diff --git a/saleor/static/dashboard-next/staff/index.tsx b/saleor/static/dashboard-next/staff/index.tsx
index 6d9b75a7a1..f657ec4f8d 100644
--- a/saleor/static/dashboard-next/staff/index.tsx
+++ b/saleor/static/dashboard-next/staff/index.tsx
@@ -4,7 +4,7 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { staffListUrl, staffMemberDetailsUrl } from "./urls";
+import { staffListUrl, staffMemberAddUrl, staffMemberDetailsUrl } from "./urls";
import StaffDetailsComponent from "./views/StaffDetails";
import StaffListComponent, { StaffListQueryParams } from "./views/StaffList";
@@ -33,11 +33,8 @@ const Component = () => (
<WindowTitle title={i18n.t("Staff")} />
<Switch>
<Route exact path={staffListUrl} component={StaffList} />
- <Route
- exact
- path={staffMemberDetailsUrl(":id")}
- component={StaffDetails}
- />
+ <Route exact path={staffMemberAddUrl} component={StaffList} />
+ <Route path={staffMemberDetailsUrl(":id")} component={StaffDetails} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/staff/urls.ts b/saleor/static/dashboard-next/staff/urls.ts
index c8e00fbbb0..9c39e968e6 100644
--- a/saleor/static/dashboard-next/staff/urls.ts
+++ b/saleor/static/dashboard-next/staff/urls.ts
@@ -2,4 +2,7 @@ import * as urlJoin from "url-join";
const staffSection = "/staff/";
export const staffListUrl = staffSection;
+export const staffMemberAddUrl = urlJoin(staffSection, "add");
export const staffMemberDetailsUrl = (id: string) => urlJoin(staffSection, id);
+export const staffMemberRemoveUrl = (id: string) =>
+ urlJoin(staffMemberDetailsUrl(id), "remove");
diff --git a/saleor/static/dashboard-next/staff/views/StaffDetails.tsx b/saleor/static/dashboard-next/staff/views/StaffDetails.tsx
index 90c2b99dc5..298aec6927 100644
--- a/saleor/static/dashboard-next/staff/views/StaffDetails.tsx
+++ b/saleor/static/dashboard-next/staff/views/StaffDetails.tsx
@@ -1,5 +1,8 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
+import { Route } from "react-router-dom";
+import ActionDialog from "../../components/ActionDialog";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
@@ -13,7 +16,11 @@ import {
import { TypedStaffMemberDetailsQuery } from "../queries";
import { StaffMemberDelete } from "../types/StaffMemberDelete";
import { StaffMemberUpdate } from "../types/StaffMemberUpdate";
-import { staffListUrl } from "../urls";
+import {
+ staffListUrl,
+ staffMemberDetailsUrl,
+ staffMemberRemoveUrl
+} from "../urls";
interface OrderListProps {
id: string;
@@ -58,7 +65,7 @@ export const StaffDetails: React.StatelessComponent<OrderListProps> = ({
<StaffDetailsPage
disabled={loading}
onBack={() => navigate(staffListUrl)}
- onDelete={deleteStaffMember}
+ onDelete={() => navigate(staffMemberRemoveUrl(id))}
onSubmit={variables =>
updateStaffMember({
variables: {
@@ -73,6 +80,29 @@ export const StaffDetails: React.StatelessComponent<OrderListProps> = ({
permissions={maybe(() => data.shop.permissions)}
staffMember={maybe(() => data.user)}
/>
+ <Route
+ path={staffMemberRemoveUrl(id)}
+ render={({ match }) => (
+ <ActionDialog
+ open={!!match}
+ title={i18n.t("Remove staff user")}
+ variant="delete"
+ onClose={() =>
+ navigate(staffMemberDetailsUrl(id))
+ }
+ onConfirm={deleteStaffMember}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ email }}</strong> from staff members?",
+ { email: maybe(() => data.user.email) }
+ )
+ }}
+ />
+ </ActionDialog>
+ )}
+ />
</>
)}
</TypedStaffMemberDeleteMutation>
diff --git a/saleor/static/dashboard-next/staff/views/StaffList.tsx b/saleor/static/dashboard-next/staff/views/StaffList.tsx
index f79627894d..144c51f9f0 100644
--- a/saleor/static/dashboard-next/staff/views/StaffList.tsx
+++ b/saleor/static/dashboard-next/staff/views/StaffList.tsx
@@ -1,16 +1,24 @@
import * as React from "react";
+import { Route } from "react-router-dom";
+import ActionDialog from "../../components/ActionDialog";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import { createPaginationState, Paginator } from "../../components/Paginator";
import i18n from "../../i18n";
import { maybe } from "../../misc";
-import { FormData as AddStaffMemberForm } from "../components/StaffAddMemberDialog";
+import StaffAddMemberDialog, {
+ FormData as AddStaffMemberForm
+} from "../components/StaffAddMemberDialog";
import StaffListPage from "../components/StaffListPage";
import { TypedStaffMemberAddMutation } from "../mutations";
import { TypedStaffListQuery } from "../queries";
import { StaffMemberAdd } from "../types/StaffMemberAdd";
-import { staffMemberDetailsUrl } from "../urls";
+import {
+ staffListUrl,
+ staffMemberAddUrl,
+ staffMemberDetailsUrl
+} from "../urls";
export type StaffListQueryParams = Partial<{
after: string;
@@ -72,25 +80,40 @@ export const StaffList: React.StatelessComponent<StaffListProps> = ({
queryString={params}
>
{({ loadNextPage, loadPreviousPage, pageInfo }) => (
- <StaffListPage
- disabled={loading || addStaffMemberData.loading}
- errors={maybe(
- () =>
- addStaffMemberData.data.staffCreate.errors,
- []
- )}
- pageInfo={pageInfo}
- staffMembers={maybe(() =>
- data.staffUsers.edges.map(edge => edge.node)
- )}
- onAdd={handleStaffMemberAdd}
- onNextPage={loadNextPage}
- onPreviousPage={loadPreviousPage}
- onRowClick={id => () =>
- navigate(
- staffMemberDetailsUrl(encodeURIComponent(id))
+ <>
+ <StaffListPage
+ disabled={loading || addStaffMemberData.loading}
+ pageInfo={pageInfo}
+ staffMembers={maybe(() =>
+ data.staffUsers.edges.map(edge => edge.node)
)}
- />
+ onAdd={() => navigate(staffMemberAddUrl)}
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ onRowClick={id => () =>
+ navigate(
+ staffMemberDetailsUrl(
+ encodeURIComponent(id)
+ )
+ )}
+ />
+ <Route
+ path={staffMemberAddUrl}
+ render={({ match }) => (
+ <StaffAddMemberDialog
+ errors={maybe(
+ () =>
+ addStaffMemberData.data.staffCreate
+ .errors,
+ []
+ )}
+ open={!!match}
+ onClose={() => navigate(staffListUrl)}
+ onConfirm={handleStaffMemberAdd}
+ />
+ )}
+ />
+ </>
)}
</Paginator>
);