Skip to content

Commit

Permalink
Fix asset import from excel files (#6182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 authored Aug 30, 2023
1 parent ce3938c commit 1523cc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/Components/Assets/AssetImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ interface Props {
const AssetImportModal = ({ open, onClose, facility }: Props) => {
const [isImporting, setIsUploading] = useState(false);
const [selectedFile, setSelectedFile] = useState<any>();
const [preview, setPreview] = useState<AssetData[]>();
const [preview, setPreview] =
useState<(AssetData & { notes?: string; last_serviced_on?: string })[]>();
const [location, setLocation] = useState("");
const [locations, setLocations] = useState<any>([]);
const dispatchAction: any = useDispatch();
Expand Down Expand Up @@ -129,8 +130,8 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
manufacturer: asset.manufacturer,
meta: { ...asset.meta },
warranty_amc_end_of_validity: asset.warranty_amc_end_of_validity,
last_serviced_on: asset.last_service.serviced_on,
note: asset.last_service.note,
last_serviced_on: asset.last_serviced_on,
note: asset.notes,
cancelToken: { promise: {} },
});

Expand Down Expand Up @@ -168,8 +169,14 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
e.preventDefault();
dragProps.setDragOver(false);
const dropedFile = e?.dataTransfer?.files[0];
if (dropedFile.type.split("/")[1] !== "json")
return dragProps.setFileDropError("Please drop a JSON file to upload!");
if (
!["xlsx", "csv", "json"].includes(
dropedFile?.name?.split(".")?.pop() || ""
)
)
return dragProps.setFileDropError(
"Please drop a JSON / Excel file to upload!"
);
setSelectedFile(dropedFile);
};

Expand Down Expand Up @@ -235,7 +242,7 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
/>
</div>
</div>
<div className="h-80 overflow-y-scroll rounded border border-gray-500 bg-white md:min-w-[500px]">
<div className="my-4 h-80 overflow-y-scroll rounded border border-gray-500 bg-white md:min-w-[500px]">
<div className="flex border-b p-2">
<div className="mr-2 p-2 font-bold">#</div>
<div className="mr-2 p-2 font-bold md:w-1/2">Name</div>
Expand Down
1 change: 0 additions & 1 deletion src/Components/Assets/AssetTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export interface AssetData {
manufacturer: string;
warranty_amc_end_of_validity: string;
last_service: AssetService;
note: string;
meta?: {
[key: string]: any;
};
Expand Down

0 comments on commit 1523cc0

Please sign in to comment.