2021-09-30 21:36:47 +00:00
|
|
|
import type { FunctionComponent } from "react";
|
2022-05-14 12:43:45 +00:00
|
|
|
import { Form, useActionData, useTransition } from "@remix-run/react";
|
2021-09-30 21:36:47 +00:00
|
|
|
|
2022-05-14 12:43:45 +00:00
|
|
|
import type { UpdateUserActionData } from "~/features/settings/actions/account";
|
|
|
|
import useSession from "~/features/core/hooks/use-session";
|
|
|
|
import Alert from "~/features/core/components/alert";
|
2021-09-30 21:36:47 +00:00
|
|
|
import Button from "../button";
|
|
|
|
import SettingsSection from "../settings-section";
|
|
|
|
|
|
|
|
const ProfileInformations: FunctionComponent = () => {
|
2022-05-21 19:33:23 +00:00
|
|
|
const { user } = useSession();
|
2022-05-14 10:22:06 +00:00
|
|
|
const transition = useTransition();
|
2022-05-14 12:43:45 +00:00
|
|
|
const actionData = useActionData<UpdateUserActionData>()?.updateUser;
|
2021-09-30 21:36:47 +00:00
|
|
|
|
2022-05-14 12:43:45 +00:00
|
|
|
const errors = actionData?.errors;
|
|
|
|
const topErrorMessage = errors?.general;
|
|
|
|
const isError = typeof topErrorMessage !== "undefined";
|
|
|
|
const isSuccess = actionData?.submitted;
|
|
|
|
const isCurrentFormTransition = transition.submission?.formData.get("_action") === "updateUser";
|
|
|
|
const isSubmitting = isCurrentFormTransition && transition.state === "submitting";
|
2021-09-30 21:36:47 +00:00
|
|
|
|
|
|
|
return (
|
2022-05-14 12:43:45 +00:00
|
|
|
<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}>
|
2022-05-14 12:43:45 +00:00
|
|
|
Save
|
2021-09-30 21:36:47 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{isError ? (
|
|
|
|
<div className="mb-8">
|
2022-05-14 12:43:45 +00:00
|
|
|
<Alert title="Oops, there was an issue" message={topErrorMessage} variant="error" />
|
2021-09-30 21:36:47 +00:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
|
2022-05-14 12:43:45 +00:00
|
|
|
{isSuccess && (
|
2021-09-30 21:36:47 +00:00
|
|
|
<div className="mb-8">
|
|
|
|
<Alert title="Saved successfully" message="Your changes have been saved." variant="success" />
|
|
|
|
</div>
|
2022-05-14 12:43:45 +00:00
|
|
|
)}
|
|
|
|
|
2021-09-30 21:36:47 +00:00
|
|
|
<div className="col-span-3 sm:col-span-2">
|
|
|
|
<label htmlFor="fullName" className="block text-sm font-medium leading-5 text-gray-700">
|
|
|
|
Full name
|
|
|
|
</label>
|
|
|
|
<div className="mt-1 rounded-md shadow-sm">
|
|
|
|
<input
|
|
|
|
id="fullName"
|
2022-05-14 10:22:06 +00:00
|
|
|
name="fullName"
|
2021-09-30 21:36:47 +00:00
|
|
|
type="text"
|
|
|
|
tabIndex={1}
|
|
|
|
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md placeholder-gray-400 focus:outline-none focus:shadow-outline-primary focus:border-primary-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"
|
2022-05-14 10:22:06 +00:00
|
|
|
defaultValue={user.fullName}
|
2021-09-30 21:36:47 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<label htmlFor="email" className="block text-sm font-medium leading-5 text-gray-700">
|
|
|
|
Email address
|
|
|
|
</label>
|
|
|
|
<div className="mt-1 rounded-md shadow-sm">
|
|
|
|
<input
|
|
|
|
id="email"
|
2022-05-14 10:22:06 +00:00
|
|
|
name="email"
|
2021-09-30 21:36:47 +00:00
|
|
|
type="email"
|
|
|
|
tabIndex={2}
|
|
|
|
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md placeholder-gray-400 focus:outline-none focus:shadow-outline-primary focus:border-primary-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"
|
2022-05-14 10:22:06 +00:00
|
|
|
defaultValue={user.email}
|
2021-09-30 21:36:47 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-14 12:43:45 +00:00
|
|
|
|
|
|
|
<input type="hidden" name="_action" value="updateUser" />
|
2021-09-30 21:36:47 +00:00
|
|
|
</SettingsSection>
|
2022-05-14 12:43:45 +00:00
|
|
|
</Form>
|
2021-09-30 21:36:47 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProfileInformations;
|