Skip to content

Commit

Permalink
feat(FormEditor): custom link for files upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nyet-ty committed Aug 3, 2023
1 parent 2af1874 commit 0372a5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/FormEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface FormEditorProps {
message?: string;
};
disableAttaches?: boolean;
uploadLink?: string;

messages?: {
attachmentsButton: string;
Expand Down Expand Up @@ -268,6 +269,7 @@ export const FormEditor = React.forwardRef<HTMLDivElement, FormEditorProps>(
onCancel,
messages = {},
disableAttaches,
uploadLink,
},
ref,
) => {
Expand All @@ -279,7 +281,7 @@ export const FormEditor = React.forwardRef<HTMLDivElement, FormEditorProps>(
const [viewValue, setViewValue] = useState<string | undefined>('');
const [popupVisible, setPopupVisibility] = useState(false);
const mounted = useMounted();
const { loading, files, uploadFiles } = useUpload();
const { loading, files, uploadFiles } = useUpload(uploadLink);
// @ts-ignore
const { getRootProps, getInputProps, isDragActive, open } = useDropzone({ onDrop: uploadFiles });
const formCtx = useContext(formContext);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';

import { formFieldName } from '../utils/upload';

export const useUpload = () => {
export const useUpload = (uploadLink?: string) => {
const [loading, setLoading] = useState(false);
const [files, setFiles] = useState<string[]>();

Expand All @@ -12,7 +12,7 @@ export const useUpload = () => {
const body = new FormData();
Array.from(files).forEach((f) => body.append(formFieldName, f));

const response = await fetch('/api/upload', {
const response = await fetch(uploadLink || '/api/upload', {
method: 'POST',
body,
});
Expand Down

0 comments on commit 0372a5d

Please sign in to comment.