From 1bded89d1e31e9452199d2af6b7f1c4d88e971a1 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Tue, 3 Dec 2019 17:39:27 +0100 Subject: [PATCH] Make it work --- .../StaffPasswordResetDialog.tsx | 4 +- src/staff/views/StaffDetails.tsx | 42 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx b/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx index 018980b25..e53521577 100644 --- a/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx +++ b/src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.tsx @@ -14,6 +14,7 @@ import ConfirmButton, { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton"; import FormSpacer from "@saleor/components/FormSpacer"; +import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors"; interface StaffPasswordResetDialogFormData { password: string; @@ -38,6 +39,7 @@ const StaffPasswordResetDialog: React.FC = ({ onSubmit }) => { const intl = useIntl(); + const dialogErrors = useModalDialogErrors(apiErrors, open); return ( @@ -47,7 +49,7 @@ const StaffPasswordResetDialog: React.FC = ({ description="dialog header" /> -
+ {({ change, data, errors, submit }) => ( <> diff --git a/src/staff/views/StaffDetails.tsx b/src/staff/views/StaffDetails.tsx index c2a165069..6efe2770a 100644 --- a/src/staff/views/StaffDetails.tsx +++ b/src/staff/views/StaffDetails.tsx @@ -15,7 +15,8 @@ import { TypedStaffAvatarDeleteMutation, TypedStaffAvatarUpdateMutation, TypedStaffMemberDeleteMutation, - TypedStaffMemberUpdateMutation + TypedStaffMemberUpdateMutation, + useChangeStaffPassword } from "../mutations"; import { TypedStaffMemberDetailsQuery } from "../queries"; import { StaffAvatarDelete } from "../types/StaffAvatarDelete"; @@ -28,6 +29,7 @@ import { StaffMemberDetailsUrlQueryParams } from "../urls"; import StaffPasswordResetDialog from "../components/StaffPasswordResetDialog"; +import { ChangeStaffPassword } from "../types/ChangeStaffPassword"; interface OrderListProps { id: string; @@ -49,6 +51,24 @@ export const StaffDetails: React.FC = ({ id, params }) => { }) ); + const handleChangePassword = (data: ChangeStaffPassword) => { + if (data.passwordChange.errors.length === 0) { + notify({ + text: intl.formatMessage(commonMessages.savedChanges) + }); + closeModal(); + } + }; + const [changePassword, changePasswordOpts] = useChangeStaffPassword({ + onCompleted: handleChangePassword + }); + + const changePasswordTransitionState = getMutationState( + changePasswordOpts.called, + changePasswordOpts.loading, + maybe(() => changePasswordOpts.data.passwordChange.errors) + ); + return ( = ({ id, params }) => { + changePasswordOpts.data.passwordChange + .errors, + [] + )} open={params.action === "change-password"} onClose={closeModal} - onSubmit={() => undefined} + onSubmit={data => + changePassword({ + variables: { + newPassword: data.password, + oldPassword: data.previousPassword + } + }) + } /> );