Skip to content

Commit

Permalink
remove dialog stories from file upload stories
Browse files Browse the repository at this point in the history
  • Loading branch information
mollpo committed Sep 2, 2024
1 parent 8f7dfa1 commit 6575faf
Showing 1 changed file with 0 additions and 103 deletions.
103 changes: 0 additions & 103 deletions src/components/files/FileUpload.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ const meta = {
<Story of={Multiple} />
</Canvas>
<Controls of={Multiple} />
<Subheading>With delete dialog</Subheading>
<Canvas>
<Story of={WithDeleteDialog} />
</Canvas>
<Controls of={WithDeleteDialog} />
</>
),
},
Expand Down Expand Up @@ -275,101 +270,3 @@ export const Multiple: Story = {
)
},
}

export const WithDeleteDialog: Story = {
render: ({ autoUpload }) => {
const { remoteFile, mutateRemoteFiles, axiosInstance } = useMockedUploadApi(
{
multipleFiles: false,
initialFile: { id: 1, name: 'file1.pdf', size: 1024 },
},
)

const onUpload = useCallback<FileUploadOnUploadSingle>(
async (file, { onProgress, onError, onSuccess }) => {
const formData = new FormData()
formData.append('file', file)

try {
await axiosInstance.post('/upload', formData, {
onUploadProgress: (event) => {
if (event.total) {
onProgress(event.loaded / event.total)
}
},
})
onSuccess()
} catch {
onError('Datei konnte nicht hochgeladen werden')
}

await mutateRemoteFiles()
},
[axiosInstance, mutateRemoteFiles],
)

const {
fileUploadObjects,
isUploading,
triggerUpload,
removeFile,
addFilesToUpload,
} = useFileUpload<CustomRemoteFile>({
remoteFile,
fileUploadObjectIsFile: (fileUploadObject, file) =>
fileUploadObject.file.name === file.name,
onUpload,
autoUpload,
})

const handleDelete = async (
fileUploadObject: FileUploadObject<CustomRemoteFile>,
) => {
if (fileUploadObject.space === FileSpace.Local) {
removeFile(fileUploadObject.file)
} else {
await axiosInstance.post('/delete')
removeFile(fileUploadObject.file)
}
}

return (
<div className="flex flex-col gap-4">
{fileUploadObjects.length === 0 && (
<FileDropZone
onSelect={addFilesToUpload}
fileTypes={['pdf']}
maxFileSize={1000000}
/>
)}
{fileUploadObjects.length > 0 && (
<FileList>
{fileUploadObjects.map((fileUploadObject) => (
<FileListItem
key={fileUploadObject.id}
fileUploadObject={fileUploadObject}
renderRemoteFileName={(remoteFile) => remoteFile.name}
renderRemoteFileSize={(remoteFile) => remoteFile.size}
disabled={
isUploading && fileUploadObject.state !== FileState.Uploading
}
fileActions={
<DeleteFileAction
fileUploadObject={fileUploadObject}
onDelete={handleDelete}
/>
}
/>
))}
</FileList>
)}

{!autoUpload && (
<Button size={Size.Md} onClick={void triggerUpload} className="mt-8">
Upload
</Button>
)}
</div>
)
},
}

0 comments on commit 6575faf

Please sign in to comment.