Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/graphql/graphql_operations_generated.json

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions app/javascript/MyProfile/MyProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Link,
LoaderFunction,
SubmitTarget,
redirect,
useFetcher,
useLoaderData,
useMatch,
Expand Down Expand Up @@ -31,7 +32,9 @@ import { AuthenticityTokensContext } from 'AuthenticityTokensContext';

export const action: ActionFunction<RouterContextProvider> = async ({ request, context }) => {
const client = context.get(apolloClientContext);
const profile = (await request.json()) as LoaderResult['initialUserConProfile'];
const { _redirectTo, ...profile } = (await request.json()) as LoaderResult['initialUserConProfile'] & {
_redirectTo?: string;
};

try {
await client.mutate({
Expand All @@ -50,6 +53,7 @@ export const action: ActionFunction<RouterContextProvider> = async ({ request, c
refetchQueries: [{ query: MyProfileQueryDocument }],
});

if (_redirectTo) return redirect(_redirectTo);
return null;
} catch (e) {
return parseResponseErrors(e, ['updateUserConProfile']);
Expand Down Expand Up @@ -225,9 +229,22 @@ function MyProfileForm() {
</div>
<div className="my-4 d-flex align-items-center">
{initialSetup ? (
<Link to="/" className="btn btn-primary">
<button
className="btn btn-primary"
disabled={mutationInProgress}
onClick={() => {
// Explicitly submit the current profile so UpdateUserConProfile sets
// needs_update=false in DB and cache, then redirect to /. Without this,
// clicking Finish without changing anything would leave needs_update=true
// and cause appRootLoader to redirect back to /my_profile/setup.
fetcher.submit({ ...userConProfile, _redirectTo: '/' } as SubmitTarget, {
method: 'PATCH',
encType: 'application/json',
});
}}
>
{t('myProfile.initialSetupFinishButton')}
</Link>
</button>
) : (
<Link to="/my_profile" className="btn btn-primary">
{t('myProfile.profileEditFinishButton')}
Expand Down
Loading
Loading