fix(onboarding): require and send the consent at registration step 5
The API refuses the first profile completion without termsAccepted, and the web app never sent it, so no analyst could finish registering. The box now always shows, with or without a link, and completing sends the consent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f111ee033a
commit
96fb709505
|
|
@ -37,9 +37,8 @@ import { SaveStatus } from './SaveStatus';
|
|||
import { StepLayout } from './StepLayout';
|
||||
|
||||
/**
|
||||
* Step 5's form for a creator, top to bottom: photo, bio, markets, links and, once there is a
|
||||
* link, the consent; «تکمیل ثبتنام» under it with the autosave line. Leaving a field saves at
|
||||
* once. The preview opens in a sheet on mobile and stays beside the form on desktop.
|
||||
* Step 5's form for a creator, top to bottom: photo, bio, markets, links and the consent;
|
||||
* «تکمیل ثبتنام» under it with the autosave line. Leaving a field saves at once. The preview opens in a sheet on mobile and stays beside the form on desktop.
|
||||
*/
|
||||
export function ProfileForm({
|
||||
page,
|
||||
|
|
@ -210,34 +209,32 @@ export function ProfileForm({
|
|||
layout={layout}
|
||||
optional
|
||||
/>
|
||||
{links.rows.length > 0 && (
|
||||
<Controller
|
||||
name="consent"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<FlexBox direction="flex-col" gap="gap-1">
|
||||
<Checkbox
|
||||
ref={field.ref}
|
||||
name={field.name}
|
||||
checked={field.value}
|
||||
onChange={(event) => field.onChange(event.target.checked)}
|
||||
onBlur={field.onBlur}
|
||||
invalid={fieldState.error != null}
|
||||
aria-describedby={
|
||||
fieldState.error ? consentErrorId : undefined
|
||||
}
|
||||
>
|
||||
{t('register.profile.links.consent')}
|
||||
</Checkbox>
|
||||
{fieldState.error && (
|
||||
<FieldError id={consentErrorId}>
|
||||
{translateMessage(t, fieldState.error.message)}
|
||||
</FieldError>
|
||||
)}
|
||||
</FlexBox>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Controller
|
||||
name="consent"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<FlexBox direction="flex-col" gap="gap-1">
|
||||
<Checkbox
|
||||
ref={field.ref}
|
||||
name={field.name}
|
||||
checked={field.value}
|
||||
onChange={(event) => field.onChange(event.target.checked)}
|
||||
onBlur={field.onBlur}
|
||||
invalid={fieldState.error != null}
|
||||
aria-describedby={
|
||||
fieldState.error ? consentErrorId : undefined
|
||||
}
|
||||
>
|
||||
{t('register.profile.links.consent')}
|
||||
</Checkbox>
|
||||
{fieldState.error && (
|
||||
<FieldError id={consentErrorId}>
|
||||
{translateMessage(t, fieldState.error.message)}
|
||||
</FieldError>
|
||||
)}
|
||||
</FlexBox>
|
||||
)}
|
||||
/>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Button
|
||||
type="submit"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { profileRepository } from '../../repositories/profile';
|
||||
import { completeCreatorProfile } from './actions';
|
||||
|
||||
vi.mock('../../repositories/profile', () => ({
|
||||
profileRepository: { saveDraft: vi.fn(), complete: vi.fn() },
|
||||
}));
|
||||
vi.mock('../../../../stores/auth', () => ({
|
||||
useAuthStore: { getState: () => ({ profileCompleted: vi.fn() }) },
|
||||
}));
|
||||
|
||||
describe('completeCreatorProfile', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('saves the form, then completes with the consent the API asks for', async () => {
|
||||
vi.mocked(profileRepository.complete).mockResolvedValue({
|
||||
creatorId: 'c1',
|
||||
} as never);
|
||||
await completeCreatorProfile({} as never, { emit: false });
|
||||
expect(profileRepository.saveDraft).toHaveBeenCalledOnce();
|
||||
expect(profileRepository.complete).toHaveBeenCalledWith({
|
||||
termsAccepted: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -10,7 +10,7 @@ import type {
|
|||
|
||||
/**
|
||||
* Ends registration step 5 for a creator: saves the form as it stands, then completes the
|
||||
* profile, which needs at least one market. Nothing is public before this; after it the creator
|
||||
* profile, which needs at least one market and the consent the form has checked. Nothing is public before this; after it the creator
|
||||
* may use the rest of the app (the session stops sending them back to step 5). Emits
|
||||
* `profile.complete`.
|
||||
*/
|
||||
|
|
@ -19,7 +19,7 @@ export async function completeCreatorProfile(
|
|||
{ emit = true }: { emit?: boolean } = {},
|
||||
): Promise<CreatorProfilePayload> {
|
||||
await profileRepository.saveDraft(args);
|
||||
const profile = await profileRepository.complete();
|
||||
const profile = await profileRepository.complete({ termsAccepted: true });
|
||||
useAuthStore.getState().profileCompleted();
|
||||
if (emit) {
|
||||
eventEmitter.emit(PROFILE_EVENTS.complete, {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import { useSessionFollowsProfile } from './use-session-follows-profile';
|
|||
/**
|
||||
* Registration step 5 for a creator, on the normal session: the public profile (photo, bio,
|
||||
* markets, links) that investors see before subscribing. It starts from the saved draft, saves as
|
||||
* it is typed, and «تکمیل ثبتنام» completes it (at least one market; the consent once there is a
|
||||
* link), then the end of registration opens. A creator who already finished goes on instead of
|
||||
* it is typed, and «تکمیل ثبتنام» completes it (at least one market and the consent), then the
|
||||
* end of registration opens. A creator who already finished goes on instead of
|
||||
* seeing the form again. A failed first read throws to the page boundary.
|
||||
*/
|
||||
export function useCreatorProfilePage({
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
toUpdateProfileDto,
|
||||
} from './mappers';
|
||||
import type {
|
||||
CompleteProfileArgs,
|
||||
CreatorProfilePayload,
|
||||
CreatorProfileResponseDto,
|
||||
SaveProfileDraftArgs,
|
||||
|
|
@ -61,10 +62,14 @@ export const profileRepository = {
|
|||
return toCreatorProfilePayload(response);
|
||||
},
|
||||
|
||||
/** Ends registration step 5. A 400 when no market is saved yet. */
|
||||
async complete(): Promise<CreatorProfilePayload> {
|
||||
/**
|
||||
* Ends registration step 5. A 400 when no market is saved yet, or at the first completion
|
||||
* without the consent (`PROFILE_TERMS_REQUIRED`).
|
||||
*/
|
||||
async complete(args: CompleteProfileArgs): Promise<CreatorProfilePayload> {
|
||||
const response = await profileHttp.post<CreatorProfileResponseDto>(
|
||||
PROFILE_ENDPOINTS.complete,
|
||||
args,
|
||||
);
|
||||
return toCreatorProfilePayload(response);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -85,6 +85,9 @@ export type UploadAvatarArgs = { avatar: File };
|
|||
* Registration step 5's autosave. Only the fields sent change; `markets` may be empty and nothing
|
||||
* counts as complete until `complete` runs.
|
||||
*/
|
||||
/** `POST /traders/me/profile/complete`: the consent the form asks for at step 5. */
|
||||
export type CompleteProfileArgs = { termsAccepted: boolean };
|
||||
|
||||
export type SaveProfileDraftArgs = {
|
||||
bio?: string;
|
||||
markets?: Market[];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
import * as v from 'valibot';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { creatorProfileSchema } from './profile-validations';
|
||||
|
||||
const profile = { bio: '', markets: ['crypto'], links: [] };
|
||||
|
||||
describe('creatorProfileSchema', () => {
|
||||
it('refuses a profile with no consent, even with no link', () => {
|
||||
const result = v.safeParse(creatorProfileSchema, {
|
||||
...profile,
|
||||
consent: false,
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.issues?.[0].message).toBe('auth:validation.consent-required');
|
||||
});
|
||||
|
||||
it('takes a profile with the consent and no link', () => {
|
||||
const result = v.safeParse(creatorProfileSchema, {
|
||||
...profile,
|
||||
consent: true,
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -72,30 +72,23 @@ export const socialLinkRow = v.pipe(
|
|||
|
||||
/**
|
||||
* A creator's public profile at registration step 5. At least one market; links are optional, and
|
||||
* the consent is required once there is one.
|
||||
* the consent is required with or without one (the API asks for it at the first completion).
|
||||
*/
|
||||
export const creatorProfileSchema = v.pipe(
|
||||
v.object({
|
||||
bio: profileBio,
|
||||
markets: v.pipe(
|
||||
v.array(v.picklist(MARKETS)),
|
||||
v.minLength(1, 'auth:validation.markets-required'),
|
||||
),
|
||||
links: v.pipe(
|
||||
v.array(socialLinkRow),
|
||||
v.maxLength(PROFILE_LIMITS.socialLinksMax, 'auth:validation.links-max'),
|
||||
),
|
||||
consent: v.boolean(),
|
||||
}),
|
||||
v.forward(
|
||||
v.partialCheck(
|
||||
[['links'], ['consent']],
|
||||
({ links, consent }) => links.length === 0 || consent,
|
||||
'auth:validation.consent-required',
|
||||
),
|
||||
['consent'],
|
||||
export const creatorProfileSchema = v.object({
|
||||
bio: profileBio,
|
||||
markets: v.pipe(
|
||||
v.array(v.picklist(MARKETS)),
|
||||
v.minLength(1, 'auth:validation.markets-required'),
|
||||
),
|
||||
);
|
||||
links: v.pipe(
|
||||
v.array(socialLinkRow),
|
||||
v.maxLength(PROFILE_LIMITS.socialLinksMax, 'auth:validation.links-max'),
|
||||
),
|
||||
consent: v.pipe(
|
||||
v.boolean(),
|
||||
v.check((consent) => consent, 'auth:validation.consent-required'),
|
||||
),
|
||||
});
|
||||
|
||||
/** An investor's optional step 5: a photo, checked when picked, and the markets they follow. */
|
||||
export const investorProfileSchema = v.object({
|
||||
|
|
|
|||
Loading…
Reference in New Issue