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:
Amiram_se 2026-11-05 19:01:42 +04:00
parent f111ee033a
commit 96fb709505
8 changed files with 108 additions and 59 deletions

View File

@ -37,9 +37,8 @@ import { SaveStatus } from './SaveStatus';
import { StepLayout } from './StepLayout'; import { StepLayout } from './StepLayout';
/** /**
* Step 5's form for a creator, top to bottom: photo, bio, markets, links and, once there is a * Step 5's form for a creator, top to bottom: photo, bio, markets, links and the consent;
* link, the consent; «تکمیل ثبت‌نام» under it with the autosave line. Leaving a field saves at * «تکمیل ثبت‌نام» 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.
* once. The preview opens in a sheet on mobile and stays beside the form on desktop.
*/ */
export function ProfileForm({ export function ProfileForm({
page, page,
@ -210,34 +209,32 @@ export function ProfileForm({
layout={layout} layout={layout}
optional optional
/> />
{links.rows.length > 0 && ( <Controller
<Controller name="consent"
name="consent" control={form.control}
control={form.control} render={({ field, fieldState }) => (
render={({ field, fieldState }) => ( <FlexBox direction="flex-col" gap="gap-1">
<FlexBox direction="flex-col" gap="gap-1"> <Checkbox
<Checkbox ref={field.ref}
ref={field.ref} name={field.name}
name={field.name} checked={field.value}
checked={field.value} onChange={(event) => field.onChange(event.target.checked)}
onChange={(event) => field.onChange(event.target.checked)} onBlur={field.onBlur}
onBlur={field.onBlur} invalid={fieldState.error != null}
invalid={fieldState.error != null} aria-describedby={
aria-describedby={ fieldState.error ? consentErrorId : undefined
fieldState.error ? consentErrorId : undefined }
} >
> {t('register.profile.links.consent')}
{t('register.profile.links.consent')} </Checkbox>
</Checkbox> {fieldState.error && (
{fieldState.error && ( <FieldError id={consentErrorId}>
<FieldError id={consentErrorId}> {translateMessage(t, fieldState.error.message)}
{translateMessage(t, fieldState.error.message)} </FieldError>
</FieldError> )}
)} </FlexBox>
</FlexBox> )}
)} />
/>
)}
<FlexBox direction="flex-col" gap="gap-3"> <FlexBox direction="flex-col" gap="gap-3">
<Button <Button
type="submit" type="submit"

View File

@ -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,
});
});
});

View File

@ -10,7 +10,7 @@ import type {
/** /**
* Ends registration step 5 for a creator: saves the form as it stands, then completes the * 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 * may use the rest of the app (the session stops sending them back to step 5). Emits
* `profile.complete`. * `profile.complete`.
*/ */
@ -19,7 +19,7 @@ export async function completeCreatorProfile(
{ emit = true }: { emit?: boolean } = {}, { emit = true }: { emit?: boolean } = {},
): Promise<CreatorProfilePayload> { ): Promise<CreatorProfilePayload> {
await profileRepository.saveDraft(args); await profileRepository.saveDraft(args);
const profile = await profileRepository.complete(); const profile = await profileRepository.complete({ termsAccepted: true });
useAuthStore.getState().profileCompleted(); useAuthStore.getState().profileCompleted();
if (emit) { if (emit) {
eventEmitter.emit(PROFILE_EVENTS.complete, { eventEmitter.emit(PROFILE_EVENTS.complete, {

View File

@ -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, * 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 * 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 * it is typed, and «تکمیل ثبت‌نام» completes it (at least one market and the consent), then the
* link), then the end of registration opens. A creator who already finished goes on instead of * 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. * seeing the form again. A failed first read throws to the page boundary.
*/ */
export function useCreatorProfilePage({ export function useCreatorProfilePage({

View File

@ -8,6 +8,7 @@ import {
toUpdateProfileDto, toUpdateProfileDto,
} from './mappers'; } from './mappers';
import type { import type {
CompleteProfileArgs,
CreatorProfilePayload, CreatorProfilePayload,
CreatorProfileResponseDto, CreatorProfileResponseDto,
SaveProfileDraftArgs, SaveProfileDraftArgs,
@ -61,10 +62,14 @@ export const profileRepository = {
return toCreatorProfilePayload(response); 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>( const response = await profileHttp.post<CreatorProfileResponseDto>(
PROFILE_ENDPOINTS.complete, PROFILE_ENDPOINTS.complete,
args,
); );
return toCreatorProfilePayload(response); return toCreatorProfilePayload(response);
}, },

View File

@ -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 * Registration step 5's autosave. Only the fields sent change; `markets` may be empty and nothing
* counts as complete until `complete` runs. * 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 = { export type SaveProfileDraftArgs = {
bio?: string; bio?: string;
markets?: Market[]; markets?: Market[];

View File

@ -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);
});
});

View File

@ -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 * 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( export const creatorProfileSchema = v.object({
v.object({ bio: profileBio,
bio: profileBio, markets: v.pipe(
markets: v.pipe( v.array(v.picklist(MARKETS)),
v.array(v.picklist(MARKETS)), v.minLength(1, 'auth:validation.markets-required'),
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'],
), ),
); 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. */ /** An investor's optional step 5: a photo, checked when picked, and the markets they follow. */
export const investorProfileSchema = v.object({ export const investorProfileSchema = v.object({