From f24c12c8f797e5c3451f4a93e4394aefd49f0098 Mon Sep 17 00:00:00 2001 From: Mayur Date: Fri, 2 Aug 2024 18:29:30 +0530 Subject: [PATCH 01/38] fix: Added mode to fetch the mode i.e manual by default --- .../get-template-details/get-template-details.usecase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/app/template/usecases/get-template-details/get-template-details.usecase.ts b/apps/api/src/app/template/usecases/get-template-details/get-template-details.usecase.ts index 7c7bf2658..c40fd838b 100644 --- a/apps/api/src/app/template/usecases/get-template-details/get-template-details.usecase.ts +++ b/apps/api/src/app/template/usecases/get-template-details/get-template-details.usecase.ts @@ -10,7 +10,7 @@ export class GetTemplateDetails { async execute(_id: string): Promise { const template = await this.templateRepository.findOne( { _id }, - '_projectId name sampleFileUrl _id totalUploads totalInvalidRecords totalRecords' + '_projectId name sampleFileUrl _id totalUploads totalInvalidRecords totalRecords mode' ); if (!template) { throw new DocumentNotFoundException('Template', _id); From 9b7b036d2f4f147add80abb85512329e0d6dfec3 Mon Sep 17 00:00:00 2001 From: Mayur Date: Fri, 2 Aug 2024 18:31:05 +0530 Subject: [PATCH 02/38] fix: Added migration to update the mode of template entity of old users as manual --- .../update-mode/update-mode.migrations.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 apps/api/src/migrations/update-mode/update-mode.migrations.ts diff --git a/apps/api/src/migrations/update-mode/update-mode.migrations.ts b/apps/api/src/migrations/update-mode/update-mode.migrations.ts new file mode 100644 index 000000000..964a5c935 --- /dev/null +++ b/apps/api/src/migrations/update-mode/update-mode.migrations.ts @@ -0,0 +1,38 @@ +import '../../config'; +import { AppModule } from '../../app.module'; + +import { NestFactory } from '@nestjs/core'; +import { TemplateRepository } from '@impler/dal'; + +export async function run() { + console.log('start migration - registering payment users'); + + let app; + try { + // Initialize the MongoDB connection + app = await NestFactory.create(AppModule, { + logger: false, + }); + + const templateRepository = new TemplateRepository(); + + // Fetch all templates without the 'mode' field + const templatesWithoutMode = await templateRepository.find({ mode: { $exists: false } }); + console.log('Templates without mode:', templatesWithoutMode); + + const updateResult = await templateRepository.update({ mode: { $exists: false } }, { mode: 'manual', multi: true }); + + console.log('Updated templates:', updateResult); + + console.log('end migration - Adding manual mode to all templates users'); + } catch (error) { + console.error('An error occurred during the migration:', error); + } finally { + if (app) { + await app.close(); + } + process.exit(0); + } +} + +run(); From 9d02d7761c8716bc9e34543a40e223c94a399335 Mon Sep 17 00:00:00 2001 From: Mayur Date: Fri, 2 Aug 2024 18:32:09 +0530 Subject: [PATCH 03/38] fix: Fetched column types label and value by function getColumnTypes --- apps/web/components/imports/forms/ColumnForm.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/components/imports/forms/ColumnForm.tsx b/apps/web/components/imports/forms/ColumnForm.tsx index e873628fd..cc2e2d6a5 100644 --- a/apps/web/components/imports/forms/ColumnForm.tsx +++ b/apps/web/components/imports/forms/ColumnForm.tsx @@ -15,13 +15,14 @@ import { } from '@mantine/core'; import { ColumnTypesEnum, DEFAULT_VALUES, IColumn } from '@impler/shared'; -import { colors, COLUMN_TYPES, DELIMITERS, MODAL_KEYS, MODAL_TITLES } from '@config'; +import { colors, DELIMITERS, MODAL_KEYS, MODAL_TITLES } from '@config'; import { Button } from '@ui/button'; import { Textarea } from '@ui/textarea'; import { Checkbox } from '@ui/checkbox'; import { MultiSelect } from '@ui/multi-select'; import { CustomSelect } from '@ui/custom-select'; +import { useSchema } from '@hooks/useSchema'; interface ColumnFormProps { data?: Partial; @@ -30,6 +31,7 @@ interface ColumnFormProps { } export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) { + const { getColumnTypes } = useSchema({ templateId: data?._templateId as string }); const { colorScheme } = useMantineColorScheme(); const { watch, @@ -107,7 +109,7 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) { render={({ field: { value, onChange, onBlur } }) => ( Date: Fri, 2 Aug 2024 19:22:05 +0530 Subject: [PATCH 06/38] feat: Fetched and return meta --- apps/web/hooks/useImportDetails.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/web/hooks/useImportDetails.tsx b/apps/web/hooks/useImportDetails.tsx index de3b5a4a7..be1e8e3d7 100644 --- a/apps/web/hooks/useImportDetails.tsx +++ b/apps/web/hooks/useImportDetails.tsx @@ -9,12 +9,14 @@ import { useAppState } from 'store/app.context'; import { ITemplate, IErrorObject, IColumn } from '@impler/shared'; import { UpdateImportForm } from '@components/imports/forms/UpdateImportForm'; import { API_KEYS, MODAL_KEYS, MODAL_TITLES, NOTIFICATION_KEYS, ROUTES } from '@config'; +import { usePlanMetaData } from 'store/planmeta.store.context'; interface useImportDetailProps { templateId: string; } export function useImportDetails({ templateId }: useImportDetailProps) { + const { meta } = usePlanMetaData(); const router = useRouter(); const queryClient = useQueryClient(); const { profileInfo } = useAppState(); @@ -107,5 +109,6 @@ export function useImportDetails({ templateId }: useImportDetailProps) { isTemplateDataLoading, onSpreadsheetImported, updateImport, + meta, }; } From d0fd22113984a84500b0585c7b67fdbd12b652f5 Mon Sep 17 00:00:00 2001 From: Mayur Date: Fri, 2 Aug 2024 19:22:43 +0530 Subject: [PATCH 07/38] feat: Setted plan meta by data.meta --- apps/web/hooks/usePlanDetails.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/web/hooks/usePlanDetails.tsx b/apps/web/hooks/usePlanDetails.tsx index d2970ee32..b9aa65ab8 100644 --- a/apps/web/hooks/usePlanDetails.tsx +++ b/apps/web/hooks/usePlanDetails.tsx @@ -2,12 +2,14 @@ import { useQuery } from '@tanstack/react-query'; import { commonApi } from '@libs/api'; import { API_KEYS } from '@config'; import { IErrorObject } from '@impler/shared'; +import { usePlanMetaData } from 'store/planmeta.store.context'; interface UsePlanDetailProps { email: string; } export function usePlanDetails({ email }: UsePlanDetailProps) { + const { meta, setPlanMeta } = usePlanMetaData(); const { data: activePlanDetails, isLoading: isActivePlanLoading } = useQuery< unknown, IErrorObject, @@ -17,12 +19,23 @@ export function usePlanDetails({ email }: UsePlanDetailProps) { [API_KEYS.FETCH_ACTIVE_SUBSCRIPTION, email], () => commonApi(API_KEYS.FETCH_ACTIVE_SUBSCRIPTION as any, {}), { + onSuccess(data) { + if (data && data.meta) { + setPlanMeta({ + AUTOMATIC_IMPORTS: data.meta.AUTOMATIC_IMPORTS, + IMAGE_UPLOAD: data.meta.IMAGE_UPLOAD, + IMPORTED_ROWS: data.meta.IMPORTED_ROWS, + REMOVE_BRANDING: data.meta.REMOVE_BRANDING, + }); + } + }, enabled: !!email, } ); return { activePlanDetails, + meta, isActivePlanLoading, }; } From b06faa2089c47a602b6bc95c620b3e4fb3c25df0 Mon Sep 17 00:00:00 2001 From: Mayur Date: Fri, 2 Aug 2024 19:23:37 +0530 Subject: [PATCH 08/38] feat: Dynamically disabling the Automatic select field based on false value --- apps/web/pages/imports/[id].tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web/pages/imports/[id].tsx b/apps/web/pages/imports/[id].tsx index 537c9a2fc..e2dce2dfd 100644 --- a/apps/web/pages/imports/[id].tsx +++ b/apps/web/pages/imports/[id].tsx @@ -24,6 +24,7 @@ import { FourIcon } from '@assets/icons/Four.icon'; import { ThreeIcon } from '@assets/icons/Three.icon'; import { DeleteIcon } from '@assets/icons/Delete.icon'; import { LeftArrowIcon } from '@assets/icons/LeftArrow.icon'; +import { TemplateModeEnum } from '@impler/shared'; const Editor = dynamic(() => import('@components/imports/editor').then((mod) => mod.OutputEditor), { ssr: false, @@ -45,6 +46,7 @@ export default function ImportDetails({}) { isTemplateDataLoading, onSpreadsheetImported, updateImport, + meta, } = useImportDetails({ templateId: router.query.id as string, }); @@ -62,6 +64,7 @@ export default function ImportDetails({}) { }); showWidget({ colorScheme }); }; + console.log(templateData?.mode); return ( @@ -83,8 +86,11 @@ export default function ImportDetails({}) { size="sm" maw={125} placeholder="Mode" - data={IMPORT_MODES} - value={templateData?.mode} + data={IMPORT_MODES.map((mode) => ({ + ...mode, + disabled: mode.value === TemplateModeEnum.AUTOMATIC && !meta?.AUTOMATIC_IMPORTS ? true : false, + }))} + value={templateData?.mode || TemplateModeEnum.MANUAL} onChange={(mode) => updateImport({ mode: mode || undefined })} />