-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: rename PrivacyFilter to RedactableValues
- Loading branch information
Showing
5 changed files
with
357 additions
and
0 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,59 @@ | ||
import { Button } from "@tradetrust-tt/tradetrust-ui-components"; | ||
import React, { FunctionComponent } from "react"; | ||
import patternWaves from "/static/images/pattern-waves.png"; | ||
|
||
interface SelectiveRedaction { | ||
editable: boolean; | ||
onToggleEditable: () => void; | ||
options?: { | ||
className?: string; | ||
description?: string; | ||
buttonText?: string; | ||
}; | ||
} | ||
|
||
export const SelectiveRedaction: FunctionComponent<SelectiveRedaction> = ({ | ||
editable, | ||
onToggleEditable, | ||
options, | ||
}) => { | ||
const defaultOptions = { | ||
className: | ||
"print:hidden bg-cover bg-cerulean-500 text-white rounded-lg p-4 mb-8", | ||
description: `Remove sensitive information on this document by clicking on the edit button. Downloaded document remains valid.`, | ||
buttonText: "Edit Document", | ||
}; | ||
const { className, description, buttonText } = options ?? defaultOptions; | ||
|
||
return ( | ||
<div | ||
className={className} | ||
style={{ backgroundImage: `url(${patternWaves})` }} | ||
> | ||
<div className="container"> | ||
<div className="md:flex items-center"> | ||
<div className="grow mb-4 md:mb-0 mr-0 md:mr-4"> | ||
<h3 className="font-normal"> | ||
The document allows fields to be selectively disclosed. | ||
</h3> | ||
<p>{description}</p> | ||
</div> | ||
<Button | ||
onClick={onToggleEditable} | ||
className="bg-white text-cerulean-500 hover:bg-gray-50 whitespace-nowrap" | ||
> | ||
{editable ? "Done" : buttonText} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const IconRedact: FunctionComponent = () => { | ||
return ( | ||
<span className="transition-colors ease-out duration-200 text-red-600 hover:text-red-700 font-normal text-sm inline-block"> | ||
[Remove] | ||
</span> | ||
); | ||
}; |
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 "./RedactableValues"; |
20 changes: 20 additions & 0 deletions
20
src/templates/examples/TemplateB/TemplateBWithRedactableValues.stories.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,20 @@ | ||
import React, { FunctionComponent } from "react"; | ||
import { TemplateBWithRedactableValues } from "./TemplateBWithRedactableValues"; | ||
import { TemplateBSampleV2 } from "./sampleV2"; | ||
|
||
export default { | ||
title: "TemplateB", | ||
component: TemplateBWithRedactableValues, | ||
parameters: { | ||
componentSubtitle: "Sample Template B", | ||
}, | ||
}; | ||
|
||
export const TemplateWithRedactableValues: FunctionComponent = () => { | ||
return ( | ||
<TemplateBWithRedactableValues | ||
document={TemplateBSampleV2} | ||
handleObfuscation={() => {}} | ||
/> | ||
); | ||
}; |
276 changes: 276 additions & 0 deletions
276
src/templates/examples/TemplateB/TemplateBWithRedactableValues.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,276 @@ | ||
import styled from "@emotion/styled"; | ||
import { | ||
RedactableValue, | ||
TemplateProps, | ||
} from "@tradetrust-tt/decentralized-renderer-react-components"; | ||
import { format } from "date-fns"; | ||
import React, { FunctionComponent, useState } from "react"; | ||
import { DocumentQrCode } from "../../../core/DocumentQrCode"; | ||
import { Wrapper } from "../../../core/Wrapper"; | ||
import { IconRedact, RedactableValues } from "../../../core/RedactableValues"; | ||
import { getDocumentData } from "../../../utils"; | ||
import { TemplateB, TemplateBSchema } from "./types"; | ||
|
||
const CustomStyles = styled.div` | ||
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; | ||
position: relative; | ||
h1 { | ||
color: #4172af; | ||
font-size: 40px; | ||
font-weight: 700; | ||
} | ||
h2 { | ||
color: #4172af; | ||
font-size: 28px; | ||
font-weight: 700; | ||
} | ||
.bg-blue { | ||
background-color: #4172af; | ||
color: #fff; | ||
} | ||
th { | ||
background-color: #4172af; | ||
color: white; | ||
} | ||
.table-responsive { | ||
overflow-x: auto; | ||
-webkit-overflow-scrolling: touch; | ||
} | ||
`; | ||
|
||
export const TemplateBWithRedactableValues: FunctionComponent< | ||
TemplateProps<TemplateBSchema> | ||
> = ({ document, handleObfuscation }) => { | ||
const [editable, setEditable] = useState(false); | ||
const documentData = getDocumentData(document) as TemplateB; | ||
const { | ||
id, | ||
date, | ||
customerId, | ||
terms, | ||
billFrom, | ||
billTo, | ||
billableItems, | ||
subtotal = 0, | ||
tax = 0, | ||
taxTotal = 0, | ||
total = 0, | ||
} = documentData; | ||
const qrCodeUrl = documentData?.links?.self.href; | ||
return ( | ||
<> | ||
<Wrapper data-testid="invoice-template"> | ||
<RedactableValues | ||
editable={editable} | ||
onToggleEditable={() => setEditable(!editable)} | ||
/> | ||
<CustomStyles> | ||
<div className="flex flex-wrap"> | ||
<div className="w-full md:w-5/12 mb-4 md:mb-0 md:ml-auto md:order-2"> | ||
<h1 className="md:text-right leading-none mb-6">INVOICE</h1> | ||
<div className="flex flex-wrap bg-blue text-center"> | ||
<div className="w-1/2 py-1"> | ||
<p>INVOICE #</p> | ||
</div> | ||
<div className="w-1/2 py-1"> | ||
<p>DATE</p> | ||
</div> | ||
</div> | ||
<div className="flex flex-wrap text-center"> | ||
<div className="w-1/2 py-1"> | ||
<p>{id}</p> | ||
</div> | ||
<div className="w-1/2 py-1"> | ||
<p>{date && format(new Date(date), "d MMM yyyy")}</p> | ||
</div> | ||
</div> | ||
<div className="flex flex-wrap bg-blue text-center"> | ||
<div className="w-1/2 py-1"> | ||
<p>CUSTOMER ID</p> | ||
</div> | ||
<div className="w-1/2 py-1"> | ||
<p>TERMS</p> | ||
</div> | ||
</div> | ||
<div className="flex flex-wrap text-center"> | ||
<div className="w-1/2 py-1"> | ||
<p>{customerId}</p> | ||
</div> | ||
<div className="w-1/2 py-1">{terms}</div> | ||
</div> | ||
</div> | ||
<div className="w-full md:w-5/12 md:order-1"> | ||
<div className="mb-4"> | ||
<h2> | ||
<RedactableValue | ||
editable={editable} | ||
value={billFrom?.name} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billFrom.name`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</h2> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billFrom?.streetAddress} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billFrom.streetAddress`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
{billFrom?.city} | ||
{billFrom?.postalCode && `, `} | ||
<RedactableValue | ||
editable={editable} | ||
value={billFrom?.postalCode} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billFrom.postalCode`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billFrom?.phoneNumber} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billFrom.phoneNumber`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
</div> | ||
<div className="flex flex-wrap bg-blue"> | ||
<div className="pl-2"> | ||
<p>BILL TO</p> | ||
</div> | ||
</div> | ||
<div className="flex flex-wrap"> | ||
<div className="mb-4 py-2"> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billTo.name} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billTo.name`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billTo.company.name} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billTo.company.name`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billTo.company.streetAddress} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billTo.company.streetAddress`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
{billTo.company.city} | ||
{billTo.company.postalCode && `, `} | ||
<RedactableValue | ||
editable={editable} | ||
value={billTo.company.postalCode} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billTo.company.postalCode`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billTo.company.phoneNumber} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billTo.company.phoneNumber`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
<p> | ||
<RedactableValue | ||
editable={editable} | ||
value={billTo.email} | ||
onRedactionRequested={() => | ||
handleObfuscation(`billTo.email`) | ||
} | ||
iconRedact={<IconRedact />} | ||
/> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="flex flex-wrap mb-4 md:mb-0" /> | ||
<div className="table-responsive mb-4"> | ||
<table className="table-auto w-full border"> | ||
<thead> | ||
<tr> | ||
<th className="px-4 py-2 text-left">DESCRIPTION</th> | ||
<th className="px-4 py-2 text-center">QTY</th> | ||
<th className="px-4 py-2 text-right">UNIT PRICE</th> | ||
<th className="px-4 py-2 text-right">AMOUNT</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{billableItems?.map((item, index) => { | ||
return ( | ||
<tr key={index}> | ||
<td className="border px-4 py-2">{item.description}</td> | ||
<td className="border px-4 py-2 text-center"> | ||
{item.quantity} | ||
</td> | ||
<td className="border px-4 py-2 text-right"> | ||
{item.unitPrice} | ||
</td> | ||
<td className="border px-4 py-2 text-right"> | ||
{" "} | ||
{item.amount} | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
</div> | ||
<div className="w-full md:w-5/12 md:ml-auto mt-2 flex text-right"> | ||
<div className="w-full md:w-1/2"> | ||
<p className="font-bold">SUBTOTAL</p> | ||
<p className="font-bold">TAX (${tax}%)</p> | ||
<hr /> | ||
<p className="font-bold">BALANCE DUE</p> | ||
</div> | ||
<div className="w-full md:w-1/2"> | ||
<p>{subtotal}</p> | ||
<p>{taxTotal && taxTotal}</p> | ||
<hr /> | ||
<p className="font-bold">{total}</p> | ||
</div> | ||
</div> | ||
{qrCodeUrl && <DocumentQrCode url={qrCodeUrl} />} | ||
</CustomStyles> | ||
</Wrapper> | ||
</> | ||
); | ||
}; |