Skip to content

Commit

Permalink
fix: Terminate import calling API with undefined (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Jan 31, 2024
2 parents 2a36e13 + 11a815b commit 4a8da5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 1 addition & 4 deletions apps/widget/src/components/widget/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { logAmplitudeEvent, resetAmplitude } from '@amplitude';

export function Widget() {
const defaultDataCount = 0;
const [phase, setPhase] = useState<PhasesEum>(PhasesEum.VALIDATE);
const { terminateUpload } = useWidget();
const { terminateUpload, phase, setPhase } = useWidget();
const [dataCount, setDataCount] = useState<number>(defaultDataCount);
const [promptContinueAction, setPromptContinueAction] = useState<PromptModalTypesEnum>();
const { showWidget, setShowWidget, reset: resetAppState, uploadInfo, templateInfo, title } = useAppState();
Expand All @@ -33,7 +32,6 @@ export function Widget() {
setPromptContinueAction(undefined);
ParentWindow.UploadTerminated({ uploadId: uploadInfo._id });
if (promptContinueAction === PromptModalTypesEnum.CLOSE) closeWidget();
resetProgress();
};
const onPromptCancel = () => {
setPromptContinueAction(undefined);
Expand All @@ -45,7 +43,6 @@ export function Widget() {
const closeWidget = () => {
setShowWidget(false);
resetAmplitude();
resetProgress();
setTimeout(() => {
ParentWindow.Close();
}, variables.closeDelayInMS);
Expand Down
17 changes: 15 additions & 2 deletions apps/widget/src/hooks/useWidget.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import { useState } from 'react';
import { useMutation } from '@tanstack/react-query';

import { PhasesEum } from '@types';
import { IErrorObject, IUpload } from '@impler/shared';
import { useAppState } from '@store/app.context';
import { useAPIState } from '@store/api.context';

export function useWidget() {
const { api } = useAPIState();
const { uploadInfo } = useAppState();
const { reset: resetAppState, uploadInfo } = useAppState();
const [phase, setPhase] = useState<PhasesEum>(PhasesEum.VALIDATE);

const { mutate: terminateUpload } = useMutation<IUpload, IErrorObject, void, string[]>(
['terminate', uploadInfo._id],
() => api.terminateUpload(uploadInfo._id)
() => api.terminateUpload(uploadInfo._id),
{
onSuccess: () => {
resetAppState();
setPhase(PhasesEum.VALIDATE);
},
}
);

return {
phase,
setPhase,
terminateUpload,
};
}

0 comments on commit 4a8da5e

Please sign in to comment.