Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Connect staff list component to API
dominik-zeglen692a5f38c840
diff --git a/saleor/static/dashboard-next/configuration/index.tsx b/saleor/static/dashboard-next/configuration/index.tsxindex f850b54243..1901a2e611 100644--- a/saleor/static/dashboard-next/configuration/index.tsx+++ b/saleor/static/dashboard-next/configuration/index.tsx@@ -11,6 +11,7 @@ import Navigation from "../icons/Navigation";import Pages from "../icons/Pages";import StoreMall from "../icons/StoreMall";import { productTypeListUrl } from "../productTypes";+import { staffListUrl } from "../staff";import ConfigurationPage from "./ConfigurationPage";export const configurationMenu = [@@ -30,7 +31,8 @@ export const configurationMenu = [description: i18n.t("Manage your employees and their permissions"),disabled: true,icon: <AccountCircle fontSize="inherit" />,- title: i18n.t("Staff Members")+ title: i18n.t("Staff Members"),+ url: staffListUrl},{description: i18n.t("Manage how you ship out orders."),diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsxindex 1e29e1141a..a913681f53 100644--- a/saleor/static/dashboard-next/index.tsx+++ b/saleor/static/dashboard-next/index.tsx@@ -26,6 +26,7 @@ import OrdersSection from "./orders";import PageSection from "./pages";import ProductSection from "./products";import ProductTypesSection from "./productTypes";+import StaffSection from "./staff";import theme from "./theme";const cookies = new Cookies();@@ -96,6 +97,7 @@ render(path="/productTypes"component={ProductTypesSection}/>+ <Route path="/staff" component={StaffSection} /><Routeexactpath="/configuration"diff --git a/saleor/static/dashboard-next/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx b/saleor/static/dashboard-next/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsxindex a106a92c7a..91b29b86c4 100644--- a/saleor/static/dashboard-next/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx+++ b/saleor/static/dashboard-next/staff/components/StaffAddMemberDialog/StaffAddMemberDialog.tsx@@ -8,15 +8,17 @@ import TextField from "@material-ui/core/TextField";import Typography from "@material-ui/core/Typography";import * as React from "react";+import { UserError } from "../../..";import { ControlledCheckbox } from "../../../components/ControlledCheckbox";import Form from "../../../components/Form";import i18n from "../../../i18n";-interface FormData {+export interface FormData {email: string;fullAccess: boolean;}interface StaffAddMemberDialogProps {+ errors: UserError[];open: boolean;onClose: () => void;onConfirm: (data: FormData) => void;@@ -41,20 +43,22 @@ const decorate = withStyles(theme => ({}}));const StaffAddMemberDialog = decorate<StaffAddMemberDialogProps>(- ({ classes, open, onClose, onConfirm }) => (+ ({ classes, errors, open, onClose, onConfirm }) => (<Dialog open={open}>- <Form initial={initialForm} onSubmit={onConfirm}>- {({ change, data, hasChanged }) => (+ <Form errors={errors} initial={initialForm} onSubmit={onConfirm}>+ {({ change, data, errors: formErrors, hasChanged }) => (<><DialogTitle>{i18n.t("Add Staff Member")}</DialogTitle><DialogContent><TextField+ error={!!formErrors.email}fullWidth+ helperText={formErrors.email}label={i18n.t("E-mail")}name="email"- onChange={change}type="email"value={data.email}+ onChange={change}/></DialogContent><hr className={classes.hr} />diff --git a/saleor/static/dashboard-next/staff/components/StaffList/StaffList.tsx b/saleor/static/dashboard-next/staff/components/StaffList/StaffList.tsxindex 2ed4e45919..b2c13887fa 100644--- a/saleor/static/dashboard-next/staff/components/StaffList/StaffList.tsx+++ b/saleor/static/dashboard-next/staff/components/StaffList/StaffList.tsx@@ -68,6 +68,7 @@ const StaffList = decorate<StaffListProps>([classes.tableRow]: !!staffMember})}hover={!!staffMember}+ onClick={!!staffMember ? onRowClick(staffMember.id) : undefined}key={staffMember ? staffMember.id : "skeleton"}><TableCell>diff --git a/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx b/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsxindex 66fe5a5fbd..4b17631a0a 100644--- a/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx+++ b/saleor/static/dashboard-next/staff/components/StaffListPage/StaffListPage.tsx@@ -2,21 +2,26 @@ import Button from "@material-ui/core/Button";import AddIcon from "@material-ui/icons/Add";import * as React from "react";-import { Omit, PageListProps } from "../../..";+import { ListProps, Omit, UserError } from "../../..";import { Container } from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import Toggle from "../../../components/Toggle";import i18n from "../../../i18n";import { StaffList_staffUsers_edges_node } from "../../types/StaffList";-import StaffAddMemberDialog from "../StaffAddMemberDialog/StaffAddMemberDialog";+import StaffAddMemberDialog, {+ FormData as AddStaffMemberForm+} from "../StaffAddMemberDialog/StaffAddMemberDialog";import StaffList from "../StaffList/StaffList";-export interface StaffListPageProps extends PageListProps {+export interface StaffListPageProps extends ListProps {+ errors: UserError[];staffMembers: Array<Omit<StaffList_staffUsers_edges_node, "__typename">>;+ onAdd: (data: AddStaffMemberForm) => void;}const StaffListPage: React.StatelessComponent<StaffListPageProps> = ({disabled,+ errors,pageInfo,staffMembers,onAdd,@@ -47,6 +52,7 @@ const StaffListPage: React.StatelessComponent<StaffListPageProps> = ({onRowClick={onRowClick}/><StaffAddMemberDialog+ errors={errors}open={openedAddStaffMemberDialog}onClose={toggleAddStaffMemberDialog}onConfirm={onAdd}diff --git a/saleor/static/dashboard-next/staff/index.tsx b/saleor/static/dashboard-next/staff/index.tsxnew file mode 100644index 0000000000..13b49618f8--- /dev/null+++ b/saleor/static/dashboard-next/staff/index.tsx@@ -0,0 +1,30 @@+import { parse as parseQs } from "qs";+import * as React from "react";+import { Route, RouteComponentProps, Switch } from "react-router-dom";++import StaffListComponent from "./views/StaffList";++const StaffList: React.StatelessComponent<RouteComponentProps<{}>> = ({+ location+}) => {+ const qs = parseQs(location.search.substr(1));+ const params = {+ after: qs.after,+ before: qs.before+ };+ return <StaffListComponent params={params} />;+};++const Component = ({ match }) => (+ <Switch>+ <Route exact path={match.url} component={StaffList} />+ </Switch>+);++export const staffListUrl = "/staff/";++export const staffMemberDetailsUrl = (id: string) => {+ return `/staff/${id}/`;+};++export default Component;diff --git a/saleor/static/dashboard-next/staff/mutations.ts b/saleor/static/dashboard-next/staff/mutations.tsnew file mode 100644index 0000000000..b061e10a33--- /dev/null+++ b/saleor/static/dashboard-next/staff/mutations.ts@@ -0,0 +1,27 @@+import gql from "graphql-tag";++import { TypedMutation } from "../mutations";+import { staffMemberDetailsFragment } from "./queries";+import {+ StaffMemberAdd,+ StaffMemberAddVariables+} from "./types/StaffMemberAdd";++const staffMemberAddMutation = gql`+ ${staffMemberDetailsFragment}+ mutation StaffMemberAdd($input: StaffCreateInput!) {+ staffCreate(input: $input) {+ errors {+ field+ message+ }+ user {+ ...StaffMemberDetailsFragment+ }+ }+ }+`;+export const TypedStaffMemberAddMutation = TypedMutation<+ StaffMemberAdd,+ StaffMemberAddVariables+>(staffMemberAddMutation);diff --git a/saleor/static/dashboard-next/staff/queries.ts b/saleor/static/dashboard-next/staff/queries.tsindex bf12f50b5d..0086387e68 100644--- a/saleor/static/dashboard-next/staff/queries.ts+++ b/saleor/static/dashboard-next/staff/queries.ts@@ -26,6 +26,12 @@ export const staffMemberDetailsFragment = gql`const staffList = gql`${staffMemberFragment}query StaffList($first: Int, $after: String, $last: Int, $before: String) {+ shop {+ permissions {+ code+ name+ }+ }staffUsers(before: $before, after: $after, first: $first, last: $last) {edges {cursordiff --git a/saleor/static/dashboard-next/staff/types/StaffList.ts b/saleor/static/dashboard-next/staff/types/StaffList.tsindex b4c68eab6a..e9a939ca50 100644--- a/saleor/static/dashboard-next/staff/types/StaffList.ts+++ b/saleor/static/dashboard-next/staff/types/StaffList.ts@@ -5,6 +5,17 @@// GraphQL query operation: StaffList// ====================================================+export interface StaffList_shop_permissions {+ __typename: "PermissionDisplay";+ code: string;+ name: string;+}++export interface StaffList_shop {+ __typename: "Shop";+ permissions: (StaffList_shop_permissions | null)[];+}+export interface StaffList_staffUsers_edges_node {__typename: "User";id: string;@@ -33,6 +44,7 @@ export interface StaffList_staffUsers {}export interface StaffList {+ shop: StaffList_shop | null;staffUsers: StaffList_staffUsers | null;}diff --git a/saleor/static/dashboard-next/staff/types/StaffMemberAdd.ts b/saleor/static/dashboard-next/staff/types/StaffMemberAdd.tsnew file mode 100644index 0000000000..a2a35631d8--- /dev/null+++ b/saleor/static/dashboard-next/staff/types/StaffMemberAdd.ts@@ -0,0 +1,42 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { StaffCreateInput } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: StaffMemberAdd+// ====================================================++export interface StaffMemberAdd_staffCreate_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface StaffMemberAdd_staffCreate_user_permissions {+ __typename: "PermissionDisplay";+ code: string;+ name: string;+}++export interface StaffMemberAdd_staffCreate_user {+ __typename: "User";+ id: string;+ email: string;+ isActive: boolean;+ permissions: (StaffMemberAdd_staffCreate_user_permissions | null)[] | null;+}++export interface StaffMemberAdd_staffCreate {+ __typename: "StaffCreate";+ errors: (StaffMemberAdd_staffCreate_errors | null)[] | null;+ user: StaffMemberAdd_staffCreate_user | null;+}++export interface StaffMemberAdd {+ staffCreate: StaffMemberAdd_staffCreate | null;+}++export interface StaffMemberAddVariables {+ input: StaffCreateInput;+}diff --git a/saleor/static/dashboard-next/staff/views/StaffList.tsx b/saleor/static/dashboard-next/staff/views/StaffList.tsxnew file mode 100644index 0000000000..67553f16a3--- /dev/null+++ b/saleor/static/dashboard-next/staff/views/StaffList.tsx@@ -0,0 +1,102 @@+import * as React from "react";++import { staffListUrl, staffMemberDetailsUrl } from "..";+import Messages from "../../components/messages";+import Navigator from "../../components/Navigator";+import i18n from "../../i18n";+import { createPaginationData, createPaginationState, maybe } from "../../misc";+import { FormData as AddStaffMemberForm } from "../components/StaffAddMemberDialog";+import StaffListPage from "../components/StaffListPage";+import { TypedStaffMemberAddMutation } from "../mutations";+import { TypedStaffListQuery } from "../queries";+import { StaffMemberAdd } from "../types/StaffMemberAdd";++interface OrderListProps {+ params: {+ after?: string;+ before?: string;+ };+}++const PAGINATE_BY = 20;++export const OrderList: React.StatelessComponent<OrderListProps> = ({+ params+}) => (+ <Navigator>+ {navigate => (+ <Messages>+ {pushMessage => {+ const paginationState = createPaginationState(PAGINATE_BY, params);+ return (+ <TypedStaffListQuery variables={paginationState}>+ {({ data, loading }) => {+ const {+ loadNextPage,+ loadPreviousPage,+ pageInfo+ } = createPaginationData(+ navigate,+ paginationState,+ staffListUrl,+ maybe(() => data.staffUsers.pageInfo),+ loading+ );+ const handleStaffMemberAddSuccess = (data: StaffMemberAdd) => {+ if (!maybe(() => data.staffCreate.errors.length)) {+ pushMessage({+ text: i18n.t("Succesfully added staff member")+ });+ navigate(staffMemberDetailsUrl(data.staffCreate.user.id));+ }+ };+ return (+ <TypedStaffMemberAddMutation+ onCompleted={handleStaffMemberAddSuccess}+ >+ {(addStaffMember, addStaffMemberData) => {+ const handleStaffMemberAdd = (+ variables: AddStaffMemberForm+ ) =>+ addStaffMember({+ variables: {+ input: {+ email: variables.email,+ permissions: variables.fullAccess+ ? data.shop.permissions.map(perm => perm.code)+ : undefined,+ sendPasswordEmail: true+ }+ }+ });+ return (+ <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(id))}+ />+ );+ }}+ </TypedStaffMemberAddMutation>+ );+ }}+ </TypedStaffListQuery>+ );+ }}+ </Messages>+ )}+ </Navigator>+);++export default OrderList;diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex 13de3c28e3..ef2697282a 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -407,6 +407,13 @@ export interface ProductTypeInput {taxRate?: TaxRateType | null;}+export interface StaffCreateInput {+ email?: string | null;+ note?: string | null;+ permissions?: (string | null)[] | null;+ sendPasswordEmail?: boolean | null;+}+//==============================================================// END Enums and Input Objects//==============================================================