-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from dump-hr/book-of-standards-pdf-upload
Book of standards pdf upload
- Loading branch information
Showing
11 changed files
with
235 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ | |
"breakpoints": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/sponsor/src/api/company/useCompanyRemoveBookOfStandards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import toast from 'react-hot-toast'; | ||
import { useMutation, useQueryClient } from 'react-query'; | ||
|
||
import { api } from '..'; | ||
|
||
const companyRemoveBookOfStandards = async () => { | ||
return await api.delete('/company/book-of-standards'); | ||
}; | ||
|
||
export const useCompanyRemoveBookOfStandards = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation(companyRemoveBookOfStandards, { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries(['company', 'current']); | ||
toast.success('Knjiga standarda uspješno izbrisana'); | ||
}, | ||
onError: (error: string) => { | ||
toast.error(error); | ||
}, | ||
}); | ||
}; |
25 changes: 25 additions & 0 deletions
25
apps/sponsor/src/api/company/useCompanyUpdateBookOfStandards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import toast from 'react-hot-toast'; | ||
import { useMutation, useQueryClient } from 'react-query'; | ||
|
||
import { api } from '..'; | ||
|
||
const companyUpdateBookOfStandards = async (file: File) => { | ||
const data = new FormData(); | ||
data.append('file', file); | ||
|
||
return await api.patchForm('company/book-of-standards', data); | ||
}; | ||
|
||
export const useCompanyUpdateBookOfStandards = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation(companyUpdateBookOfStandards, { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries(['company', 'current']); | ||
toast.success('Knjiga standarda uspješno uploadana'); | ||
}, | ||
onError: (error: string) => { | ||
toast.error(error); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useDropzone } from 'react-dropzone'; | ||
import toast from 'react-hot-toast'; | ||
|
||
import RemoveSvg from '../../assets/icons/remove.svg'; | ||
import UploadSvg from '../../assets/icons/upload.svg'; | ||
import c from '../PhotoInput/PhotoInput.module.scss'; | ||
|
||
type PdfInputProps = { | ||
label?: string; | ||
fileSrc?: string; | ||
isDisabled?: boolean; | ||
height?: number; | ||
handleUpload: (files: File[]) => void; | ||
handleRemove: () => void; | ||
}; | ||
|
||
export const PdfInput: React.FC<PdfInputProps> = ({ | ||
label, | ||
fileSrc, | ||
isDisabled = false, | ||
height = 300, | ||
handleRemove, | ||
handleUpload, | ||
}) => { | ||
const { getRootProps, getInputProps } = useDropzone({ | ||
accept: { 'application/pdf': [] }, | ||
onDrop: async (acceptedFiles) => { | ||
if (!acceptedFiles) { | ||
toast.error('PDF file is required'); | ||
return; | ||
} | ||
handleUpload(acceptedFiles); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className={c.inputArea} style={{ height: `${height}px` }}> | ||
<div className={c.inputAreaContainer} style={{ height: `${height}px` }}> | ||
{!fileSrc && ( | ||
<div className={c.inputField} {...getRootProps()}> | ||
<input disabled={isDisabled} {...getInputProps()} /> | ||
<div className={c.inputFieldLabel}> | ||
<img src={UploadSvg} alt='Upload' /> | ||
<p>{label}</p> | ||
</div> | ||
</div> | ||
)} | ||
|
||
<aside className={c.thumbsContainer}> | ||
{!!fileSrc && ( | ||
<div className={c.inputFieldLabel}>Knjiga standarda spremljena</div> | ||
)} | ||
</aside> | ||
|
||
{!!fileSrc && ( | ||
<button className={c.removeButton} onClick={() => handleRemove()}> | ||
<img className={c.removeSvg} src={RemoveSvg} alt='Ukloni' /> | ||
<p>Ukloni</p> | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PdfInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters