Skip to content

Commit

Permalink
Signup flow configuration (#2876)
Browse files Browse the repository at this point in the history
* feat(signup): add job title and additional info to signup form

- Introduce optional job title field in signup form schema
- Modify user creation logic to include additional information
- Update UI to accommodate new form structure

(Your signup form is expanding faster than my collection of dad jokes)

* feat(database): add DBA column to Business model and migration

- Introduce a new 'dba' column to the Business schema
- Create migration for adding the 'dba' column in the database

(Your database schema has more additions than my Netflix watchlist)

* fix(ui-definition): correct URL formatting in collection flow event

- Update URLs to remove unnecessary closing curly braces
- Ensure consistent formatting across multiple files

(your code is like a URL with a typo—hard to reach the destination)

---------

Co-authored-by: Alon Peretz <[email protected]>
  • Loading branch information
tomer-shvadron and alonp99 authored Dec 5, 2024
1 parent 43d2bdd commit a0601f5
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 21 deletions.
1 change: 1 addition & 0 deletions apps/kyb-app/src/common/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ITheme {
poweredBy?: boolean;
};
signup?: {
showJobTitle?: boolean;
companyLogo: {
imageSrc?: string;
styles?: CSSProperties;
Expand Down
2 changes: 1 addition & 1 deletion apps/kyb-app/src/components/layouts/AppShell/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
}

export const AppShell = ({ children }: Props) => {
return <div className="w-ful flex h-screen flex-nowrap">{children}</div>;
return <div className="flex h-screen w-full flex-nowrap">{children}</div>;
};

AppShell.FormContainer = FormContainer;
Expand Down
2 changes: 1 addition & 1 deletion apps/kyb-app/src/components/layouts/AppShell/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
export const Sidebar = ({ children }: Props) => {
return (
<div
className="bg-primary text-primary-foreground col-span-2 flex h-screen w-[24%] max-w-[418px] flex-col px-14 pb-4 pt-14"
className="bg-primary text-primary-foreground flex h-screen w-[24rem] flex-col p-10"
id="sidebar"
>
{children}
Expand Down
12 changes: 10 additions & 2 deletions apps/kyb-app/src/domains/collection-flow/collection-flow.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,16 @@ export interface CreateEndUserDto {
email: string;
firstName: string;
lastName: string;
additionalInfo?: Record<string, unknown>;
}

export const createEndUserRequest = async ({ email, firstName, lastName }: CreateEndUserDto) => {
await request.post('collection-flow/no-user', { json: { email, firstName, lastName } });
export const createEndUserRequest = async ({
email,
firstName,
lastName,
additionalInfo,
}: CreateEndUserDto) => {
await request.post('collection-flow/no-user', {
json: { email, firstName, lastName, additionalInfo },
});
};
11 changes: 7 additions & 4 deletions apps/kyb-app/src/pages/CollectionFlow/CollectionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ export const CollectionFlow = withSessionProtected(() => {
<AppShell.Sidebar>
<div className="flex h-full flex-col">
<div className="flex h-full flex-1 flex-col">
<div className="flex flex-col gap-8 pb-10">
<div className="flex justify-start">
<div className="flex justify-between gap-8 pb-10">
<AppShell.Navigation />
<div className="flex w-full justify-end">
<AppShell.LanguagePicker />
</div>
<AppShell.Navigation />
</div>
<div className="pb-10">
{customer?.logoImageUri && (
Expand Down Expand Up @@ -233,7 +233,10 @@ export const CollectionFlow = withSessionProtected(() => {
{themeDefinition.ui?.poweredBy !== false && (
<div className="flex flex-col">
<div className="border-b pb-12" />
<PoweredByLogo className="mt-8" sidebarRootId="sidebar" />
<PoweredByLogo
className="mt-8 max-w-[10rem]"
sidebarRootId="sidebar"
/>
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { JsonSchemaRuleEngine } from '@/components/organisms/DynamicUI/rule-engi
import { CreateEndUserDto } from '@/domains/collection-flow';
import { transformRJSFErrors } from '@/helpers/transform-errors';
import { baseLayouts, DynamicForm } from '@ballerine/ui';
import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';
import { toast } from 'sonner';
import { Submit } from './components/Submit';
import { useCreateEndUserMutation } from './hooks/useCreateEndUserMutation';
import { signupFormSchema, signupFormUiSchema } from './signup-form-schema';
import { useSignupLayout } from '@/common/components/layouts/Signup';

const layouts = {
...baseLayouts,
Expand All @@ -18,6 +19,12 @@ const layouts = {

export const SignUpForm = () => {
const { createEndUserRequest, isLoading } = useCreateEndUserMutation();
const { themeParams } = useSignupLayout();

const signupSchema = useMemo(
() => signupFormSchema({ jobTitle: themeParams?.showJobTitle }),
[themeParams?.showJobTitle],
);

const handleSubmit = useCallback(
(values: Record<string, any>) => {
Expand All @@ -26,7 +33,7 @@ export const SignUpForm = () => {
const isValid = (values: unknown): values is CreateEndUserDto => {
return jsonValidator.test(values, {
type: 'json-schema',
value: signupFormSchema,
value: signupSchema,
});
};

Expand All @@ -36,12 +43,12 @@ export const SignUpForm = () => {
toast.error('Invalid form values. Something went wrong.');
}
},
[createEndUserRequest],
[createEndUserRequest, signupSchema],
);

return (
<DynamicForm
schema={signupFormSchema}
schema={signupSchema}
uiSchema={signupFormUiSchema}
onSubmit={handleSubmit}
transformErrors={transformRJSFErrors}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { RJSFSchema, UiSchema } from '@rjsf/utils';

export const signupFormSchema: RJSFSchema = {
export const signupFormSchema: (props: { jobTitle?: boolean }) => RJSFSchema = ({
jobTitle,
} = {}) => ({
type: 'object',
required: ['firstName', 'lastName', 'email'],
properties: {
Expand All @@ -20,7 +22,27 @@ export const signupFormSchema: RJSFSchema = {
format: 'email',
maxLength: 254,
},
additionalInfo: {
type: 'object',
default: {},
required: [...[jobTitle ? 'jobTitle' : null]].filter(Boolean),
properties: {
...(jobTitle
? {
jobTitle: {
type: 'string',
title: 'Job Title',
maxLength: 50,
},
}
: {}),
},
},
},
};
});

export const signupFormUiSchema: UiSchema = {};
export const signupFormUiSchema: UiSchema = {
additionalInfo: {
'ui:label': false,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Business" ADD COLUMN "dba" TEXT;
1 change: 1 addition & 0 deletions services/workflows-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ model Business {
companyName String // Official registered name of the business entity
registrationNumber String? // Unique registration number assigned by the relevant authorities
legalForm String? // Legal structure of the business entity, e.g., LLC, corporation, partnership
dba String? // Doing Business As (DBA) name of the business entity
country String?
countryOfIncorporation String? // Country where the business entity is incorporated
dateOfIncorporation DateTime? // Date when the business entity was incorporated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const definition = {
{
name: 'send_collection_flow_finished',
pluginKind: 'api',
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/send-event}`,
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/send-event`,
method: 'POST',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {query.token}' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const definition = {
{
name: 'send_collection_flow_finished',
pluginKind: 'api',
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/send-event}`,
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/send-event`,
method: 'POST',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {query.token}' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const definition = {
{
name: 'send_collection_flow_finished',
pluginKind: 'api',
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/send-event}`,
url: `{collectionFlow.config.apiUrl}/api/v1/collection-flow/send-event`,
method: 'POST',
stateNames: ['finish'],
headers: { Authorization: 'Bearer {query.token}' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export class CollectionFlowNoUserController {
}

@common.Post()
async signUp(@TokenScope() tokenScope: ITokenScope, @common.Body() payload: SignupDto) {
async signUp(
@TokenScope() tokenScope: ITokenScope,
@common.Body() { additionalInfo, ...payload }: SignupDto,
) {
try {
const { workflowDefinitionId, context } =
await this.workflowService.getWorkflowRuntimeDataById(
Expand All @@ -70,7 +73,12 @@ export class CollectionFlowNoUserController {
await this.prismaService.$transaction(async transaction => {
const endUser = await this.endUserService.create(
{
data: { ...payload, projectId: tokenScope.projectId },
data: {
...payload,
// @ts-ignore -- known issue with Prisma's JSON type
additionalInfo,
projectId: tokenScope.projectId,
},
},
transaction,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString, MaxLength } from 'class-validator';
import { IsEmail, IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';

export class SignupDto {
@ApiProperty({ required: true, type: String })
Expand All @@ -19,4 +19,8 @@ export class SignupDto {
@IsNotEmpty()
@MaxLength(254)
email!: string;

@ApiProperty({ required: false })
@IsOptional()
additionalInfo?: Record<string, unknown>;
}

0 comments on commit a0601f5

Please sign in to comment.