-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
B 2747 create od generation invoice panel (#640)
- Loading branch information
Showing
9 changed files
with
128 additions
and
3 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
6 changes: 6 additions & 0 deletions
6
...lows/request-payment-flow/_panels/generate-invoice/_translations/generate-invoice.en.json
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,6 @@ | ||
{ | ||
"alert": { | ||
"title": "Please double check that everything is correct", | ||
"description": "Once approved it will trigger the payment process and can’t be edited." | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shared/panels/_flows/request-payment-flow/_panels/generate-invoice/generate-invoice.hooks.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,5 @@ | ||
import { useSinglePanelContext } from "@/shared/features/side-panels/side-panel/side-panel"; | ||
|
||
export function useGenerateInvoice() { | ||
return useSinglePanelContext("generate-invoice"); | ||
} |
104 changes: 104 additions & 0 deletions
104
shared/panels/_flows/request-payment-flow/_panels/generate-invoice/generate-invoice.tsx
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,104 @@ | ||
import { Info } from "lucide-react"; | ||
import { useMemo } from "react"; | ||
|
||
import { Button } from "@/design-system/atoms/button/variants/button-default"; | ||
import { Skeleton } from "@/design-system/atoms/skeleton"; | ||
import { Alert } from "@/design-system/molecules/alert"; | ||
|
||
import { ErrorState } from "@/shared/components/error-state/error-state"; | ||
import { useInvoicePreview } from "@/shared/features/invoice/hooks/use-invoice-preview/use-invoice-preview"; | ||
import { useInvoiceUpload } from "@/shared/features/invoice/hooks/use-invoice-upload/use-invoice-upload"; | ||
import InvoiceViewer from "@/shared/features/invoice/viewer/invoice-viewer"; | ||
import { SidePanelBody } from "@/shared/features/side-panels/side-panel-body/side-panel-body"; | ||
import { SidePanelFooter } from "@/shared/features/side-panels/side-panel-footer/side-panel-footer"; | ||
import { SidePanelHeader } from "@/shared/features/side-panels/side-panel-header/side-panel-header"; | ||
import { useSidePanel } from "@/shared/features/side-panels/side-panel/side-panel"; | ||
import { useGenerateInvoice } from "@/shared/panels/_flows/request-payment-flow/_panels/generate-invoice/generate-invoice.hooks"; | ||
import { useRequestPaymentFlow } from "@/shared/panels/_flows/request-payment-flow/request-payment-flow.context"; | ||
import { Translate } from "@/shared/translation/components/translate/translate"; | ||
|
||
function Content() { | ||
const { billingProfileId = "", rewardIds } = useRequestPaymentFlow(); | ||
|
||
const { | ||
isLoading: isLoadingInvoicePreview, | ||
isError, | ||
fileBlob, | ||
fileUrl, | ||
invoiceId, | ||
} = useInvoicePreview({ | ||
rewardIds, | ||
billingProfileId, | ||
isSample: false, | ||
}); | ||
|
||
const { isPendingUploadInvoice, handleSendInvoice } = useInvoiceUpload({ | ||
billingProfileId, | ||
invoiceId, | ||
}); | ||
|
||
const renderInvoicePreview = useMemo(() => { | ||
if (isLoadingInvoicePreview) { | ||
return ( | ||
<div className={"grid gap-md"}> | ||
<Skeleton classNames={{ base: "h-16" }} /> | ||
<Skeleton classNames={{ base: "h-16" }} /> | ||
<Skeleton classNames={{ base: "h-16" }} /> | ||
<Skeleton classNames={{ base: "h-16" }} /> | ||
</div> | ||
); | ||
} | ||
if (isError) { | ||
return <ErrorState />; | ||
} | ||
if (fileUrl) { | ||
return <InvoiceViewer fileUrl={fileUrl} />; | ||
} | ||
return null; | ||
}, [isLoadingInvoicePreview, isError, fileUrl]); | ||
|
||
return ( | ||
<> | ||
<SidePanelHeader | ||
title={{ | ||
translate: { | ||
// TODO update title | ||
token: "panels:singleContributionSelection.title", | ||
}, | ||
}} | ||
canClose | ||
/> | ||
|
||
<SidePanelBody> | ||
<Alert | ||
color="grey" | ||
title={<Translate token="panels:generateInvoice.alert.title" />} | ||
description={<Translate token="panels:generateInvoice.alert.description" />} | ||
icon={{ component: Info }} | ||
/> | ||
{renderInvoicePreview} | ||
</SidePanelBody> | ||
<SidePanelFooter> | ||
<Button | ||
variant={"secondary"} | ||
size={"md"} | ||
onClick={() => handleSendInvoice({ fileBlob })} | ||
isDisabled={!fileBlob} | ||
isLoading={isPendingUploadInvoice} | ||
translate={{ token: "common:form.send" }} | ||
/> | ||
</SidePanelFooter> | ||
</> | ||
); | ||
} | ||
|
||
export function GenerateInvoice() { | ||
const { name } = useGenerateInvoice(); | ||
const { Panel } = useSidePanel({ name }); | ||
|
||
return ( | ||
<Panel> | ||
<Content /> | ||
</Panel> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
shared/panels/_flows/request-payment-flow/_panels/generate-invoice/generate-invoice.types.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 @@ | ||
export interface GenerateInvoiceProps {} |
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