Skip to content

Commit

Permalink
feat onboarding (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Mar 14, 2024
2 parents cd61c4e + 6250703 commit 80f532c
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 105 deletions.
12 changes: 6 additions & 6 deletions apps/api/src/app/column/commands/add-column.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AddColumnCommand extends BaseCommand {
@IsArray()
@IsOptional()
@Type(() => Array<string>)
alternateKeys: string[];
alternateKeys? = [];

@IsBoolean()
@IsOptional()
Expand All @@ -31,25 +31,25 @@ export class AddColumnCommand extends BaseCommand {

@IsString()
@IsOptional()
regex: string;
regex?: string;

@IsString()
@IsOptional()
regexDescription: string;
regexDescription?: string;

@IsArray()
@IsOptional()
@Type(() => Array<string>)
selectValues: string[];
selectValues?: string[];

@IsArray()
@IsOptional()
@Type(() => Array<string>)
dateFormats: string[];
dateFormats?: string[];

@IsNumber()
@IsOptional()
sequence: number;
sequence?: number;

@IsDefined()
@IsMongoId()
Expand Down
9 changes: 8 additions & 1 deletion apps/api/src/app/project/dtos/create-project-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsDefined, IsOptional, IsString } from 'class-validator';
import { IsBoolean, IsDefined, IsOptional, IsString } from 'class-validator';
export class CreateProjectRequestDto {
@ApiProperty({
description: 'Name of the project',
Expand All @@ -14,4 +14,11 @@ export class CreateProjectRequestDto {
@IsString()
@IsOptional()
authHeaderName: string;

@ApiPropertyOptional({
description: 'Is this project created during onboarding?',
})
@IsBoolean()
@IsOptional()
onboarding = false;
}
2 changes: 1 addition & 1 deletion apps/api/src/app/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ProjectController {
): Promise<{ project: ProjectResponseDto; environment: EnvironmentResponseDto }> {
const projectWithEnvironment = await this.createProjectUsecase.execute(
CreateProjectCommand.create({
name: body.name,
...body,
_userId: user._id,
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { IsDefined, IsString } from 'class-validator';
import { IsBoolean, IsDefined, IsString } from 'class-validator';
import { AuthenticatedCommand } from '@shared/commands/authenticated.command';

export class CreateProjectCommand extends AuthenticatedCommand {
@IsDefined()
@IsString()
name: string;

@IsBoolean()
@IsDefined()
onboarding: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { Injectable } from '@nestjs/common';
import { ProjectRepository } from '@impler/dal';
import { ColumnTypesEnum } from '@impler/shared';

import { CreateProjectCommand } from './create-project.command';
import { CreateEnvironment } from 'app/environment/usecases/create-environment/create-environment.usecase';
import { CreateEnvironment } from 'app/environment/usecases';
import { CreateTemplate, UpdateTemplateColumns } from 'app/template/usecases';

@Injectable()
export class CreateProject {
constructor(private projectRepository: ProjectRepository, private readonly createEnvironment: CreateEnvironment) {}
constructor(
private projectRepository: ProjectRepository,
private readonly createEnvironment: CreateEnvironment,
private readonly createTemplate: CreateTemplate,
private readonly updateTemplateColumns: UpdateTemplateColumns
) {}

async execute(command: CreateProjectCommand) {
const project = await this.projectRepository.create(command);
Expand All @@ -15,9 +23,100 @@ export class CreateProject {
_userId: command._userId,
});

if (command.onboarding) {
await this.createSampleImport(project._id);
}

return {
project,
environment,
};
}

async createSampleImport(_projectId: string) {
const template = await this.createTemplate.execute({
_projectId,
chunkSize: 100,
name: 'Sales Data Import',
});
await this.updateTemplateColumns.execute(
[
{
_templateId: template._id,
name: 'Date',
key: 'Date *',
type: ColumnTypesEnum.DATE,
isRequired: true,
dateFormats: ['DD/MM/YYYY'],
isUnique: false,
},
{
_templateId: template._id,
name: 'Product Name/ID',
key: 'Product Name/ID *',
type: ColumnTypesEnum.STRING,
isRequired: true,
isUnique: false,
},
{
_templateId: template._id,
name: 'Quantity',
key: 'Quantity *',
type: ColumnTypesEnum.NUMBER,
isRequired: true,
isUnique: false,
},
{
_templateId: template._id,
name: 'Total Price',
key: 'Total Price',
type: ColumnTypesEnum.NUMBER,
isRequired: false,
isUnique: false,
},
{
_templateId: template._id,
name: 'Customer Name/ID',
key: 'Customer Name/ID *',
type: ColumnTypesEnum.STRING,
isRequired: true,
isUnique: false,
},
{
_templateId: template._id,
name: 'Payment Method',
key: 'Payment Method *',
type: ColumnTypesEnum.SELECT,
selectValues: ['credit card', 'cash', 'check'],
isRequired: true,
isUnique: false,
},
{
_templateId: template._id,
name: 'Transaction ID',
key: 'Transaction ID * (unique)',
type: ColumnTypesEnum.STRING,
isRequired: true,
isUnique: true,
},
{
_templateId: template._id,
name: 'Salesperson Name/ID',
key: 'Salesperson Name/ID',
type: ColumnTypesEnum.STRING,
isRequired: false,
isUnique: false,
},
{
_templateId: template._id,
name: 'Notes/Comments',
key: 'Notes/Comments',
type: ColumnTypesEnum.STRING,
isRequired: false,
isUnique: false,
},
],
template._id
);
}
}
6 changes: 6 additions & 0 deletions apps/api/src/app/project/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { DeleteProject } from './delete-project/delete-project.usecase';
import { GetTemplates } from './get-templates/get-templates.usecase';
import { GetEnvironment } from './get-environment/get-environment.usecase';

import { CreateTemplate, UpdateTemplateColumns } from 'app/template/usecases';
import { SaveSampleFile } from '@shared/usecases/save-sample-file/save-sample-file.usecase';

export const USE_CASES = [
GetProjects,
CreateProject,
Expand All @@ -16,6 +19,9 @@ export const USE_CASES = [
GetTemplates,
GetImports,
GetEnvironment,
CreateTemplate,
SaveSampleFile,
UpdateTemplateColumns,
//
];

Expand Down
15 changes: 9 additions & 6 deletions apps/web/components/common/Support.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ if (publicRuntimeConfig.NEXT_PUBLIC_OPENREPLAY_KEY) {
tracker = new Tracker({
__DISABLE_SECURE_MODE: true,
projectKey: publicRuntimeConfig.NEXT_PUBLIC_OPENREPLAY_KEY,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
network: {
sessionTokenHeader: 'X-OpenReplay-Session-Token',
failuresOnly: true,
ignoreHeaders: ['Cookie'],
captureInIframes: true,
Expand All @@ -39,11 +40,13 @@ export function Support({ profile }: SupportProps) {
tracker.setMetadata('lastname', profile.lastName);
tracker.setMetadata('firstname', profile.firstName);
}
twakRef.current?.setAttributes({
id: profile._id,
name: profile.firstName,
email: profile.email,
});
/*
* twakRef.current?.setAttributes({
* id: profile._id,
* name: profile.firstName,
* email: profile.email,
* });
*/
}
}, [profile]);

Expand Down
8 changes: 7 additions & 1 deletion apps/web/components/imports/schema/ColumnsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function ColumnsTable({ templateId }: ColumnsTableProps) {
handleSubmit();
SelectRef.current = false;
}}
id="columns"
>
<DraggableTable<IColumn>
emptyDataText='No columns found click on "+" to add new column'
Expand Down Expand Up @@ -208,7 +209,12 @@ export function ColumnsTable({ templateId }: ColumnsTableProps) {
) : (
<td colSpan={5}>
<Tooltip label="Add new column" withArrow position="top-start">
<ActionIcon bg={colors.yellow} variant="transparent" onClick={() => setShowAddRow(true)}>
<ActionIcon
id="add-column"
bg={colors.yellow}
variant="transparent"
onClick={() => setShowAddRow(true)}
>
<AddIcon color={colors.white} />
</ActionIcon>
</Tooltip>
Expand Down
38 changes: 21 additions & 17 deletions apps/web/components/signin/CreateProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,28 @@ export default function CreateProjectForm() {
IErrorObject,
ICreateProjectData,
string[]
>([API_KEYS.PROJECT_CREATE], (data) => commonApi(API_KEYS.PROJECT_CREATE as any, { body: data }), {
onSuccess: (data) => {
if (profileInfo) {
setProfileInfo({
...profileInfo,
_projectId: data.project._id,
accessToken: data.environment.apiKeys[VARIABLES.ZERO].key,
>(
[API_KEYS.PROJECT_CREATE],
(data) => commonApi(API_KEYS.PROJECT_CREATE as any, { body: { ...data, onboarding: true } }),
{
onSuccess: (data) => {
if (profileInfo) {
setProfileInfo({
...profileInfo,
_projectId: data.project._id,
accessToken: data.environment.apiKeys[VARIABLES.ZERO].key,
});
}
track({
name: 'PROJECT CREATE',
properties: {
duringOnboard: true,
},
});
}
track({
name: 'PROJECT CREATE',
properties: {
duringOnboard: true,
},
});
push('/');
},
});
push('/');
},
}
);

const onProjectFormSubmit = (data: ICreateProjectData) => {
createProject(data);
Expand Down
3 changes: 2 additions & 1 deletion apps/web/design-system/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Tabs as MantineTabs } from '@mantine/core';
import useStyles from './Tabs.styles';

interface TabItem {
id?: string;
value: string;
title: string;
icon?: React.ReactNode;
Expand All @@ -28,7 +29,7 @@ export function Tabs({ items, keepMounted, allowTabDeactivation, defaultValue }:
>
<MantineTabs.List>
{items.map((item) => (
<MantineTabs.Tab key={item.value} value={item.value} icon={item.icon}>
<MantineTabs.Tab data-id={item.id} key={item.value} value={item.value} icon={item.icon}>
{item.title}
</MantineTabs.Tab>
))}
Expand Down
13 changes: 11 additions & 2 deletions apps/web/design-system/import-card/ImportCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IconButton } from '@ui/icon-button';
import { CopyIcon } from '@assets/icons/Copy.icon';

interface ImportCardProps {
id?: string;
href: string;
title: string;
imports: number;
Expand All @@ -15,11 +16,19 @@ interface ImportCardProps {
onDuplicateClick?: (e: MouseEvent<HTMLButtonElement>) => void;
}

export function ImportCard({ title, imports, totalRecords, errorRecords, onDuplicateClick, href }: ImportCardProps) {
export function ImportCard({
id,
title,
imports,
totalRecords,
errorRecords,
onDuplicateClick,
href,
}: ImportCardProps) {
const { classes } = useStyles();

return (
<Link href={href} className={classes.root}>
<Link id={id} href={href} className={classes.root}>
<Flex justify="space-between">
<Text size="xl" className={`title ${classes.name}`}>
{title}
Expand Down
3 changes: 3 additions & 0 deletions apps/web/hooks/useApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export function useApp() {
() => commonApi<IProfileData>(API_KEYS.ME as any, {}),
{
onSuccess(profileData) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.usetifulTags = { userId: profileData?._id };
setProfileInfo(profileData);
},
}
Expand Down
Loading

0 comments on commit 80f532c

Please sign in to comment.