Make it work
This commit is contained in:
parent
0bd2d52840
commit
1bded89d1e
2 changed files with 41 additions and 5 deletions
|
@ -14,6 +14,7 @@ import ConfirmButton, {
|
||||||
ConfirmButtonTransitionState
|
ConfirmButtonTransitionState
|
||||||
} from "@saleor/components/ConfirmButton";
|
} from "@saleor/components/ConfirmButton";
|
||||||
import FormSpacer from "@saleor/components/FormSpacer";
|
import FormSpacer from "@saleor/components/FormSpacer";
|
||||||
|
import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
|
||||||
|
|
||||||
interface StaffPasswordResetDialogFormData {
|
interface StaffPasswordResetDialogFormData {
|
||||||
password: string;
|
password: string;
|
||||||
|
@ -38,6 +39,7 @@ const StaffPasswordResetDialog: React.FC<StaffPasswordResetDialogProps> = ({
|
||||||
onSubmit
|
onSubmit
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const dialogErrors = useModalDialogErrors(apiErrors, open);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
||||||
|
@ -47,7 +49,7 @@ const StaffPasswordResetDialog: React.FC<StaffPasswordResetDialogProps> = ({
|
||||||
description="dialog header"
|
description="dialog header"
|
||||||
/>
|
/>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<Form errors={apiErrors} initial={initialForm} onSubmit={onSubmit}>
|
<Form errors={dialogErrors} initial={initialForm} onSubmit={onSubmit}>
|
||||||
{({ change, data, errors, submit }) => (
|
{({ change, data, errors, submit }) => (
|
||||||
<>
|
<>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
|
|
@ -15,7 +15,8 @@ import {
|
||||||
TypedStaffAvatarDeleteMutation,
|
TypedStaffAvatarDeleteMutation,
|
||||||
TypedStaffAvatarUpdateMutation,
|
TypedStaffAvatarUpdateMutation,
|
||||||
TypedStaffMemberDeleteMutation,
|
TypedStaffMemberDeleteMutation,
|
||||||
TypedStaffMemberUpdateMutation
|
TypedStaffMemberUpdateMutation,
|
||||||
|
useChangeStaffPassword
|
||||||
} from "../mutations";
|
} from "../mutations";
|
||||||
import { TypedStaffMemberDetailsQuery } from "../queries";
|
import { TypedStaffMemberDetailsQuery } from "../queries";
|
||||||
import { StaffAvatarDelete } from "../types/StaffAvatarDelete";
|
import { StaffAvatarDelete } from "../types/StaffAvatarDelete";
|
||||||
|
@ -28,6 +29,7 @@ import {
|
||||||
StaffMemberDetailsUrlQueryParams
|
StaffMemberDetailsUrlQueryParams
|
||||||
} from "../urls";
|
} from "../urls";
|
||||||
import StaffPasswordResetDialog from "../components/StaffPasswordResetDialog";
|
import StaffPasswordResetDialog from "../components/StaffPasswordResetDialog";
|
||||||
|
import { ChangeStaffPassword } from "../types/ChangeStaffPassword";
|
||||||
|
|
||||||
interface OrderListProps {
|
interface OrderListProps {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -49,6 +51,24 @@ export const StaffDetails: React.FC<OrderListProps> = ({ 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 (
|
return (
|
||||||
<TypedStaffMemberDetailsQuery
|
<TypedStaffMemberDetailsQuery
|
||||||
displayLoader
|
displayLoader
|
||||||
|
@ -228,11 +248,25 @@ export const StaffDetails: React.FC<OrderListProps> = ({ id, params }) => {
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
</ActionDialog>
|
</ActionDialog>
|
||||||
<StaffPasswordResetDialog
|
<StaffPasswordResetDialog
|
||||||
confirmButtonState="default"
|
confirmButtonState={
|
||||||
errors={[]}
|
changePasswordTransitionState
|
||||||
|
}
|
||||||
|
errors={maybe(
|
||||||
|
() =>
|
||||||
|
changePasswordOpts.data.passwordChange
|
||||||
|
.errors,
|
||||||
|
[]
|
||||||
|
)}
|
||||||
open={params.action === "change-password"}
|
open={params.action === "change-password"}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
onSubmit={() => undefined}
|
onSubmit={data =>
|
||||||
|
changePassword({
|
||||||
|
variables: {
|
||||||
|
newPassword: data.password,
|
||||||
|
oldPassword: data.previousPassword
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue