Skip to content

Commit

Permalink
fix: Disabled importing xls file and added support for invalid file…
Browse files Browse the repository at this point in the history
… error (#351)
  • Loading branch information
chavda-bhavik authored Aug 28, 2023
2 parents 11c1604 + d4ce60b commit af2520c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
18 changes: 14 additions & 4 deletions apps/widget/src/components/widget/Phases/Phase1/Phase1.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEXTS } from '@config';
import { TEXTS, variables } from '@config';
import { Select } from '@ui/Select';
import { Button } from '@ui/Button';
import { Dropzone } from '@ui/Dropzone';
Expand All @@ -23,6 +23,7 @@ export function Phase1(props: IPhase1Props) {
control,
templates,
onDownload,
setError,
isUploadLoading,
onTemplateChange,
showSelectTemplate,
Expand All @@ -34,7 +35,7 @@ export function Phase1(props: IPhase1Props) {

return (
<>
<LoadingOverlay visible={!isInitialDataLoaded || isUploadLoading} />
<LoadingOverlay visible={!isInitialDataLoaded} />
<Group className={classes.templateContainer} spacing="lg" noWrap>
{showSelectTemplate && (
<Controller
Expand Down Expand Up @@ -72,9 +73,18 @@ export function Phase1(props: IPhase1Props) {
}}
render={({ field, fieldState }) => (
<Dropzone
loading={isUploadLoading}
onReject={() => {
setError('file', {
message: `File type not supported! Please select a .csv or .xlsx file.`,
type: 'manual',
});
}}
className={classes.dropzone}
// eslint-disable-next-line no-magic-numbers
onDrop={(selectedFile) => field.onChange(selectedFile[0])}
onDrop={(selectedFile) => {
field.onChange(selectedFile[variables.baseIndex]);
setError('file', {});
}}
onClear={() => field.onChange(undefined)}
title={TEXTS.PHASE1.SELECT_FILE}
file={field.value}
Expand Down
2 changes: 1 addition & 1 deletion apps/widget/src/config/texts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const TEXTS = {
DROPZONE: {
TITLE: 'Drop your file here or ',
BROWSE: 'Browse',
SUBTITLE: 'Select any .csv, .xlx or .xlsx file',
SUBTITLE: 'Bring any .csv or .xlsx file here to start Import',
FILE_SELECTION: 'File selected successfully',
},
PHASE1: {
Expand Down
6 changes: 4 additions & 2 deletions apps/widget/src/design-system/Dropzone/Dropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { File as FileCMP } from '../File';
interface IDropzoneProps {
loading?: boolean;
accept?: string[];
onReject?: () => void;
onDrop: (files: FileWithPath[]) => void;
onClear?: () => void;
file?: FileWithPath;
Expand All @@ -19,10 +20,11 @@ interface IDropzoneProps {
export function Dropzone(props: IDropzoneProps) {
const {
loading,
accept = [MIME_TYPES.csv, MIME_TYPES.xls, MIME_TYPES.xlsx],
accept = [MIME_TYPES.csv, MIME_TYPES.xlsx],
onDrop,
onClear,
file,
onReject,
title,
className,
error,
Expand Down Expand Up @@ -54,7 +56,7 @@ export function Dropzone(props: IDropzoneProps) {

const SelectFileContent = () => {
return (
<MantineDropzone onDrop={onDrop} accept={accept} loading={loading} classNames={classes}>
<MantineDropzone onReject={onReject} onDrop={onDrop} accept={accept} loading={loading} classNames={classes}>
<Group position="center">
<div>
<Text align="center" weight="bold">
Expand Down
2 changes: 2 additions & 0 deletions apps/widget/src/hooks/Phase1/usePhase1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function usePhase1({ goNext }: IUsePhase1Props) {
trigger,
getValues,
setValue,
setError,
handleSubmit,
formState: { errors },
} = useForm<IFormvalues>();
Expand Down Expand Up @@ -135,6 +136,7 @@ export function usePhase1({ goNext }: IUsePhase1Props) {
return {
control,
errors,
setError,
register,
templates,
onDownload,
Expand Down

0 comments on commit af2520c

Please sign in to comment.