Skip to content

Commit

Permalink
fix: Imported data count issue and sending imported data on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik committed Jul 16, 2024
1 parent 65334a5 commit 5117e53
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/widget/src/components/widget/Phases/Phase3/Phase3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SegmentedControl } from '@ui/SegmentedControl';
import { ConfirmModal } from 'components/widget/modals/ConfirmModal';

interface IPhase3Props {
onNextClick: (uploadData: IUpload) => void;
onNextClick: (uploadData: IUpload, importedData?: Record<string, any>[]) => void;
onPrevClick: () => void;
}

Expand Down
3 changes: 2 additions & 1 deletion apps/widget/src/components/widget/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ export function Widget() {
resetAppState();
setPhase(PhasesEnum.VALIDATE);
};
const onComplete = (uploadData: IUpload) => {
const onComplete = (uploadData: IUpload, importedData?: Record<string, any>[]) => {
setDataCount(uploadData.totalRecords);
setPhase(PhasesEnum.COMPLETE);
ParentWindow.UploadCompleted(uploadData);
if (importedData) ParentWindow.DataImported(importedData);
};

const PhaseView = {
Expand Down
4 changes: 2 additions & 2 deletions apps/widget/src/hooks/Phase3/usePhase3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SelectEditor } from './SelectEditor';
import { MultiSelectEditor } from './MultiSelectEditor';

interface IUsePhase3Props {
onNext: (uploadData: IUpload) => void;
onNext: (uploadData: IUpload, importedData?: Record<string, any>[]) => void;
}

const defaultPage = 1;
Expand Down Expand Up @@ -218,7 +218,7 @@ export function usePhase3({ onNext }: IUsePhase3Props) {
records: uploadData.uploadInfo.totalRecords - uploadData.uploadInfo.invalidRecords,
});
setUploadInfo(uploadData.uploadInfo);
onNext(uploadData.uploadInfo);
onNext(uploadData.uploadInfo, uploadData.importedData);
},
onError(error: IErrorObject) {
notifier.showError({ message: error.message, title: error.error });
Expand Down
3 changes: 3 additions & 0 deletions apps/widget/src/util/parent-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export function UploadTerminated(value: { uploadId: string }) {
export function UploadCompleted(value: IUpload) {
window.parent.postMessage({ type: EventTypesEnum.UPLOAD_COMPLETED, value }, '*');
}
export function DataImported(value: Record<string, any>[]) {
window.parent.postMessage({ type: EventTypesEnum.DATA_IMPORTED, value }, '*');
}
1 change: 1 addition & 0 deletions libs/shared/src/types/widget/widget.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export enum EventTypesEnum {
UPLOAD_STARTED = 'UPLOAD_STARTED',
UPLOAD_TERMINATED = 'UPLOAD_TERMINATED',
UPLOAD_COMPLETED = 'UPLOAD_COMPLETED',
DATA_IMPORTED = 'DATA_IMPORTED',
}
6 changes: 4 additions & 2 deletions packages/react/src/hooks/useImpler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export function useImpler({
if (onUploadTerminate) onUploadTerminate(eventData.value);
break;
case EventTypesEnum.UPLOAD_COMPLETED:
if (onDataImported) onDataImported(eventData.value.importedData);
if (onUploadComplete) onUploadComplete(eventData.value.uploadInfo);
if (onUploadComplete) onUploadComplete(eventData.value);
break;
case EventTypesEnum.DATA_IMPORTED:
if (onDataImported) onDataImported(eventData.value);
break;
case EventTypesEnum.CLOSE_WIDGET:
if (onWidgetClose) onWidgetClose();
Expand Down
23 changes: 6 additions & 17 deletions packages/react/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IUpload } from '@impler/shared';
import { IUpload, EventTypesEnum } from '@impler/shared';

export interface ButtonProps {
projectId: string;
Expand Down Expand Up @@ -36,18 +36,6 @@ export type UploadTemplateData = {
};
export type UploadData = { uploadId: string };

export enum EventTypesEnum {
INIT_IFRAME = 'INIT_IFRAME',
SHOW_WIDGET = 'SHOW_WIDGET',
WIDGET_READY = 'WIDGET_READY',
CLOSE_WIDGET = 'CLOSE_WIDGET',
AUTHENTICATION_VALID = 'AUTHENTICATION_VALID',
AUTHENTICATION_ERROR = 'AUTHENTICATION_ERROR',
UPLOAD_STARTED = 'UPLOAD_STARTED',
UPLOAD_TERMINATED = 'UPLOAD_TERMINATED',
UPLOAD_COMPLETED = 'UPLOAD_COMPLETED',
}

export type EventCalls =
| {
type: EventTypesEnum.UPLOAD_STARTED;
Expand All @@ -59,10 +47,11 @@ export type EventCalls =
}
| {
type: EventTypesEnum.UPLOAD_COMPLETED;
value: {
uploadInfo: IUpload;
importedData: Record<string, any>[];
};
value: IUpload;
}
| {
type: EventTypesEnum.DATA_IMPORTED;
value: Record<string, any>[];
}
| {
type: EventTypesEnum.CLOSE_WIDGET;
Expand Down

0 comments on commit 5117e53

Please sign in to comment.