shellphone.app/app/features/settings/components/account/update-password.tsx

68 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-09-30 21:36:47 +00:00
import type { FunctionComponent } from "react";
import { Form, useActionData, useTransition } from "@remix-run/react";
2021-09-30 21:36:47 +00:00
import type { ChangePasswordActionData } from "~/features/settings/actions/account";
2022-05-14 10:22:06 +00:00
import Alert from "~/features/core/components/alert";
import LabeledTextField from "~/features/core/components/labeled-text-field";
2021-09-30 21:36:47 +00:00
import Button from "../button";
import SettingsSection from "../settings-section";
const UpdatePassword: FunctionComponent = () => {
2022-05-14 10:22:06 +00:00
const transition = useTransition();
const actionData = useActionData<ChangePasswordActionData>()?.changePassword;
2021-09-30 21:36:47 +00:00
const topErrorMessage = actionData?.errors?.general;
const isError = typeof topErrorMessage !== "undefined";
const isSuccess = actionData?.submitted;
const isCurrentFormTransition = transition.submission?.formData.get("_action") === "changePassword";
const isSubmitting = isCurrentFormTransition && transition.state === "submitting";
2021-09-30 21:36:47 +00:00
return (
<Form method="post">
2021-09-30 21:36:47 +00:00
<SettingsSection
footer={
<div className="px-4 py-3 bg-gray-50 text-right text-sm font-medium sm:px-6">
<Button variant="default" type="submit" isDisabled={isSubmitting}>
Save
2021-09-30 21:36:47 +00:00
</Button>
</div>
}
>
{isError ? (
<div className="mb-8">
<Alert title="Oops, there was an issue" message={topErrorMessage} variant="error" />
2021-09-30 21:36:47 +00:00
</div>
) : null}
{isSuccess ? (
<div className="mb-8">
<Alert title="Saved successfully" message="Your changes have been saved." variant="success" />
</div>
) : null}
<LabeledTextField
name="currentPassword"
label="Current password"
type="password"
tabIndex={3}
error={actionData?.errors?.currentPassword}
disabled={isSubmitting}
/>
<LabeledTextField
name="newPassword"
label="New password"
type="password"
tabIndex={4}
error={actionData?.errors?.newPassword}
disabled={isSubmitting}
/>
<input type="hidden" name="_action" value="changePassword" />
2021-09-30 21:36:47 +00:00
</SettingsSection>
</Form>
2021-09-30 21:36:47 +00:00
);
};
export default UpdatePassword;