Skip to content

Commit

Permalink
feat: Added loading to Phase 2 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Nov 9, 2022
1 parent ae8d7c4 commit bfeb308
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions apps/widget/src/components/widget/Phases/Phase2/Phase2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { usePhase2 } from '@hooks/Phase2/usePhase2';
import { PhasesEum } from '@types';
import { Controller } from 'react-hook-form';
import { MappingHeading } from './MappingHeading';
import { LoadingOverlay } from '@ui/LoadingOverlay';

interface IPhase2Props {
onPrevClick: () => void;
Expand All @@ -17,7 +18,9 @@ export function Phase2(props: IPhase2Props) {
const { classes } = useStyles();
const { onPrevClick, onNextClick } = props;
const [wrapperHeight, setWrapperHeight] = useState(defaulWrappertHeight);
const { headings, mappings, control, onSubmit } = usePhase2({ goNext: onNextClick });
const { headings, mappings, control, onSubmit, isInitialDataLoaded, isMappingFinalizing } = usePhase2({
goNext: onNextClick,
});
const wrapperRef = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>;
const titlesRef = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>;

Expand All @@ -30,6 +33,7 @@ export function Phase2(props: IPhase2Props) {

return (
<>
<LoadingOverlay visible={!isInitialDataLoaded || isMappingFinalizing} />
<div style={{ flexGrow: 1 }} ref={wrapperRef}>
{/* Heading */}
<MappingHeading ref={titlesRef} />
Expand Down Expand Up @@ -61,7 +65,12 @@ export function Phase2(props: IPhase2Props) {
</div>
</div>

<Footer active={PhasesEum.MAPPING} onNextClick={onSubmit} onPrevClick={onPrevClick} />
<Footer
primaryButtonLoading={isMappingFinalizing}
active={PhasesEum.MAPPING}
onNextClick={onSubmit}
onPrevClick={onPrevClick}
/>
</>
);
}
7 changes: 6 additions & 1 deletion apps/widget/src/hooks/Phase2/usePhase2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export function usePhase2({ goNext }: IUsePhase2Props) {
const { api } = useAPIState();
const { uploadInfo, setUploadInfo } = useAppState();
const { control, reset, handleSubmit } = useForm<{ mappings: IMappingFinalize[] }>();
const { data: mappings } = useQuery<IMapping[], IErrorObject, IMapping[], string[]>(
const {
isFetched,
isLoading,
data: mappings,
} = useQuery<IMapping[], IErrorObject, IMapping[], string[]>(
[`mapping:${uploadInfo._id}`],
() => api.getMappings(uploadInfo._id),
{
Expand Down Expand Up @@ -50,6 +54,7 @@ export function usePhase2({ goNext }: IUsePhase2Props) {
mappings,
isMappingFinalizing,
headings: uploadInfo.headings,
isInitialDataLoaded: isFetched && !isLoading,
onSubmit: handleSubmit(onFinalizeMapping),
};
}

0 comments on commit bfeb308

Please sign in to comment.