Skip to content

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

Add customers address update diaog

dominik-zeglen0b6dedde49e1
diff --git a/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx b/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx
index 2becd77d25..0653ea114f 100644
--- a/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx
+++ b/saleor/static/dashboard-next/components/ConfirmButton/ConfirmButton.tsx
@@ -37,6 +37,8 @@ const styles = (theme: Theme) =>
opacity: 0
},
label: {
+ alignItems: "center",
+ display: "flex",
transitionDuration: theme.transitions.duration.standard + "ms"
},
progress: {
@@ -59,7 +61,6 @@ const styles = (theme: Theme) =>
export interface ConfirmButtonProps
extends Omit<ButtonProps, "classes">,
WithStyles<typeof styles> {
- children: string;
transitionState: ConfirmButtonTransitionState;
}
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx b/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx
index 0ff4c50fe2..46bb56f206 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx
@@ -16,7 +16,6 @@ import CardMenu from "../../../components/CardMenu";
import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
import { AddressTypeEnum } from "../../../types/globalTypes";
import { CustomerAddresses_user_addresses } from "../../types/CustomerAddresses";
@@ -31,12 +30,11 @@ export interface CustomerAddressProps {
onSetAsDefault: (type: AddressTypeEnum) => void;
}
-const styles = (theme: Theme) =>
- createStyles({
- actions: {
- flexDirection: "row"
- }
- });
+const styles = createStyles({
+ actions: {
+ flexDirection: "row"
+ }
+});
const CustomerAddress = withStyles(styles, { name: "CustomerAddress" })(
({
address,
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx b/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx
index 252e8c24b9..6e88d70faf 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx
@@ -4,6 +4,7 @@ import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
+import AddIcon from "@material-ui/icons/Add";
import * as React from "react";
import AddressEdit from "../../../components/AddressEdit";
@@ -14,10 +15,10 @@ import Form from "../../../components/Form";
import i18n from "../../../i18n";
import { UserError } from "../../../types";
import { AddressTypeInput } from "../../types";
-import { CustomerAddresses_user } from "../../types/CustomerAddresses";
+import { CustomerAddresses_user_addresses } from "../../types/CustomerAddresses";
export interface CustomerAddressDialogProps {
- address: AddressTypeInput;
+ address: CustomerAddresses_user_addresses;
confirmButtonState: ConfirmButtonTransitionState;
countries: Array<{
code: string;
@@ -25,7 +26,7 @@ export interface CustomerAddressDialogProps {
}>;
errors: UserError[];
open: boolean;
- user: CustomerAddresses_user;
+ variant: "create" | "edit";
onClose: () => void;
onConfirm: (data: AddressTypeInput) => void;
}
@@ -44,42 +45,61 @@ const CustomerAddressDialog = withStyles(styles, {})(
countries,
errors,
open,
- user,
+ variant,
onClose,
onConfirm
- }: CustomerAddressDialogProps & WithStyles<typeof styles>) => (
- <Dialog open={open} classes={{ paper: classes.overflow }}>
- <Form initial={address} errors={errors} onSubmit={onConfirm}>
- {({ change, data, errors, submit }) => (
- <>
- <DialogTitle>{}</DialogTitle>
- <DialogContent className={classes.overflow}>
- <AddressEdit
- countries={countries}
- data={data}
- errors={errors}
- onChange={change}
- />
- </DialogContent>
- <DialogActions>
- <Button onClick={onClose}>
- {i18n.t("Cancel", { context: "button" })}
- </Button>
- <ConfirmButton
- transitionState={confirmButtonState}
- color="primary"
- variant="contained"
- onClick={submit}
- type="submit"
- >
- {i18n.t("Confirm", { context: "button" })}
- </ConfirmButton>
- </DialogActions>
- </>
- )}
- </Form>
- </Dialog>
- )
+ }: CustomerAddressDialogProps & WithStyles<typeof styles>) => {
+ const initialForm: AddressTypeInput = {
+ ...address,
+ country: {
+ label: address.country.country,
+ value: address.country.code
+ }
+ };
+ return (
+ <Dialog
+ open={open}
+ classes={{ paper: classes.overflow }}
+ fullWidth
+ maxWidth="sm"
+ >
+ <Form initial={initialForm} errors={errors} onSubmit={onConfirm}>
+ {({ change, data, errors, submit }) => (
+ <>
+ <DialogTitle>
+ {variant === "create"
+ ? i18n.t("Add Address")
+ : i18n.t("Edit Address")}
+ </DialogTitle>
+ <DialogContent className={classes.overflow}>
+ <AddressEdit
+ countries={countries}
+ data={data}
+ errors={errors}
+ onChange={change}
+ />
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={onClose}>
+ {i18n.t("Cancel", { context: "button" })}
+ </Button>
+ <ConfirmButton
+ transitionState={confirmButtonState}
+ color="secondary"
+ variant="contained"
+ onClick={submit}
+ type="submit"
+ >
+ {i18n.t("Save Address", { context: "button" })}
+ <AddIcon />
+ </ConfirmButton>
+ </DialogActions>
+ </>
+ )}
+ </Form>
+ </Dialog>
+ );
+ }
);
CustomerAddressDialog.displayName = "CustomerAddressDialog";
export default CustomerAddressDialog;
diff --git a/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx b/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx
index 0d9a91d7c6..36e78c6018 100644
--- a/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx
+++ b/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx
@@ -3,6 +3,8 @@ import * as React from "react";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
+import useNavigator from "../../hooks/useNavigator";
+import useNotifier from "../../hooks/useNotifier";
import i18n from "../../i18n";
import { maybe } from "../../misc";
import CustomerAddressListPage from "../components/CustomerAddressListPage";
@@ -14,39 +16,41 @@ interface CustomerAddressesProps {
id: string;
}
-const CustomerAddresses: React.FC<CustomerAddressesProps> = ({ id }) => (
- <Navigator>
- {navigate => (
- <Messages>
- {pushMessage => {
- return (
- <TypedSetCustomerDefaultAddressMutation>
- {(setCustomerDefaultAddress, setCustomerDefaultAddressOpts) => (
- <TypedCustomerAddressesQuery variables={{ id }}>
- {customerData => {
- return (
- <CustomerAddressListPage
- customer={maybe(() => customerData.data.user)}
- disabled={customerData.loading}
- onAdd={() => undefined}
- onBack={() =>
- navigate(customerUrl(customerData.data.user.id))
- }
- onEdit={() => undefined}
- onRemove={() => undefined}
- onSetAsDefault={(id, type) =>
- setCustomerDefaultAddress({ variables: { id, type } })
- }
- />
- );
- }}
- </TypedCustomerAddressesQuery>
- )}
- </TypedSetCustomerDefaultAddressMutation>
- );
- }}
- </Messages>
- )}
- </Navigator>
-);
+const CustomerAddresses: React.FC<CustomerAddressesProps> = ({ id }) => {
+ const navigate = useNavigator();
+ const notify = useNotifier();
+
+ return (
+ <TypedSetCustomerDefaultAddressMutation>
+ {(setCustomerDefaultAddress, setCustomerDefaultAddressOpts) => (
+ <TypedCustomerAddressesQuery variables={{ id }}>
+ {customerData => {
+ return (
+ <>
+ <WindowTitle
+ title={maybe(() => customerData.data.user.firstName)}
+ />
+ <CustomerAddressListPage
+ customer={maybe(() => customerData.data.user)}
+ disabled={customerData.loading}
+ onAdd={() => undefined}
+ onBack={() =>
+ navigate(customerUrl(customerData.data.user.id))
+ }
+ onEdit={() => undefined}
+ onRemove={() => undefined}
+ onSetAsDefault={(id, type) =>
+ setCustomerDefaultAddress({
+ variables: { id, type }
+ })
+ }
+ />
+ </>
+ );
+ }}
+ </TypedCustomerAddressesQuery>
+ )}
+ </TypedSetCustomerDefaultAddressMutation>
+ );
+};
export default CustomerAddresses;
diff --git a/saleor/static/dashboard-next/fixtures.ts b/saleor/static/dashboard-next/fixtures.ts
index ef8ab6255c..e935638285 100644
--- a/saleor/static/dashboard-next/fixtures.ts
+++ b/saleor/static/dashboard-next/fixtures.ts
@@ -22,3 +22,11 @@ export const pageListProps: { [key: string]: PageListProps } = {
pageInfo
}
};
+
+export const countries = [
+ { code: "AF", label: "Afghanistan" },
+ { code: "AX", label: "Åland Islands" },
+ { code: "AL", label: "Albania" },
+ { code: "DZ", label: "Algeria" },
+ { code: "AS", label: "American Samoa" }
+];
diff --git a/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx b/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx
index c4a9c7f838..6ac535c5ac 100644
--- a/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx
@@ -4,10 +4,22 @@ import * as React from "react";
import CustomerAddressDialog, {
CustomerAddressDialogProps
} from "../../../customers/components/CustomerAddressDialog";
+import { customer } from "../../../customers/fixtures";
+import { countries } from "../../../fixtures";
import Decorator from "../../Decorator";
-const props: CustomerAddressDialogProps = {};
+const props: CustomerAddressDialogProps = {
+ address: customer.addresses[0],
+ confirmButtonState: "default",
+ countries,
+ errors: [],
+ onClose: () => undefined,
+ onConfirm: () => undefined,
+ open: true,
+ variant: "create"
+};
storiesOf("Customers / Address editing dialog", module)
.addDecorator(Decorator)
- .add("default", () => <CustomerAddressDialog {...props} />);
+ .add("default", () => <CustomerAddressDialog {...props} />)
+ .add("edit", () => <CustomerAddressDialog {...props} variant="edit" />);