-
Notifications
You must be signed in to change notification settings - Fork 182
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 #563 from Fuciuss/feature/import-invoice-from-JSON
Feature - import invoice from json
- Loading branch information
Showing
5 changed files
with
414 additions
and
307 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
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,54 @@ | ||
"use client" | ||
|
||
import { useRef } from 'react'; | ||
import { BaseButton } from '@/app/components'; | ||
import { useInvoiceContext } from '@/contexts/InvoiceContext'; | ||
import { Import } from 'lucide-react'; | ||
|
||
type ImportJsonButtonType = { | ||
setOpen: (open: boolean) => void; | ||
} | ||
|
||
const ImportJsonButton = ({ setOpen }: ImportJsonButtonType) => { | ||
const fileInputRef = useRef<HTMLInputElement>(null); | ||
const { importInvoice, invoicePdfLoading } = useInvoiceContext(); | ||
|
||
const handleClick = () => { | ||
fileInputRef.current?.click(); | ||
}; | ||
|
||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files?.[0]; | ||
if (file && file.type === 'application/json') { | ||
importInvoice(file); | ||
setOpen(false); | ||
} | ||
// Reset input value to allow selecting the same file again | ||
if (fileInputRef.current) { | ||
fileInputRef.current.value = ''; | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<input | ||
type="file" | ||
ref={fileInputRef} | ||
onChange={handleFileChange} | ||
accept=".json" | ||
style={{ display: 'none' }} | ||
/> | ||
<BaseButton | ||
variant="outline" | ||
tooltipLabel="Import JSON invoice" | ||
disabled={invoicePdfLoading} | ||
onClick={handleClick} | ||
> | ||
<Import /> | ||
Import JSON | ||
</BaseButton> | ||
</> | ||
); | ||
}; | ||
|
||
export default ImportJsonButton; |
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
Oops, something went wrong.