Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import BaseNavbar from "./layout/BaseNavbar";
import BaseFooter from "./layout/BaseFooter";

/* =========================
* Settings
========================= */
import { SettingsPanel } from "./settings/SettingsPanel";

/* =========================
* Invoice
========================= */
Expand Down Expand Up @@ -44,6 +49,7 @@ import FinalPdf from "./invoice/actions/FinalPdf";
import CurrencySelector from "./reusables/form-fields/CurrencySelector";
import FormInput from "./reusables/form-fields/FormInput";
import FormTextarea from "./reusables/form-fields/FormTextarea";
import FormSelect from "./reusables/form-fields/FormSelect";
import DatePickerFormField from "./reusables/form-fields/DatePickerFormField";
import FormFile from "./reusables/form-fields/FormFile";
import ChargeInput from "./reusables/form-fields/ChargeInput";
Expand Down Expand Up @@ -101,6 +107,7 @@ import DevDebug from "./dev/DevDebug";
export {
BaseNavbar,
BaseFooter,
SettingsPanel,
InvoiceMain,
InvoiceForm,
InvoiceActions,
Expand All @@ -123,6 +130,7 @@ export {
FinalPdf,
FormInput,
FormTextarea,
FormSelect,
DatePickerFormField,
FormFile,
ChargeInput,
Expand Down
24 changes: 23 additions & 1 deletion app/components/invoice/actions/PdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,44 @@ import { FinalPdf, LivePreview } from "@/app/components";

// Contexts
import { useInvoiceContext } from "@/contexts/InvoiceContext";
import { useSettings } from "@/contexts/SettingsContext";

// Types
import { InvoiceType } from "@/types";

const PdfViewer = () => {
const { invoicePdf } = useInvoiceContext();
const { settings } = useSettings();

const { watch } = useFormContext<InvoiceType>();

const [debouncedWatch] = useDebounce(watch, 1000);
const formValues = debouncedWatch();

// Clean data based on settings - remove discount/tax if settings are disabled
const cleanedData = {
...formValues,
details: {
...formValues.details,
items: formValues.details.items.map(item => {
const cleanedItem = { ...item };
if (!settings.discountPerItem.enabled) {
cleanedItem.discount = undefined;
cleanedItem.discountType = undefined;
}
if (!settings.taxPerItem.enabled) {
cleanedItem.tax = undefined;
cleanedItem.taxType = undefined;
}
return cleanedItem;
})
}
};

return (
<div className="my-3">
{invoicePdf.size == 0 ? (
<LivePreview data={formValues} />
<LivePreview data={cleanedData} />
) : (
<FinalPdf />
)}
Comment thread
NickDabizaz marked this conversation as resolved.
Expand Down
46 changes: 26 additions & 20 deletions app/components/invoice/form/Charges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ChargeInput } from "@/app/components";
// Contexts
import { useChargesContext } from "@/contexts/ChargesContext";
import { useTranslationContext } from "@/contexts/TranslationContext";
import { useSettings } from "@/contexts/SettingsContext";

// Helpers
import { formatNumberWithCommas } from "@/lib/helpers";
Expand All @@ -26,6 +27,7 @@ const Charges = () => {
} = useFormContext<InvoiceType>();

const { _t } = useTranslationContext();
const { settings } = useSettings();

const {
discountSwitch,
Expand Down Expand Up @@ -63,35 +65,39 @@ const Charges = () => {
<div className="flex flex-col gap-3 min-w-[20rem]">
{/* Switches */}
<div className="flex justify-evenly pb-6">
<div>
<Label>{_t("form.steps.summary.discount")}</Label>

{!settings.discountPerItem.enabled && (
<div>
<Label>{_t("form.steps.summary.discount")}</Label>

<div>
<Switch
checked={discountSwitch}
onCheckedChange={(value) => {
setDiscountSwitch(value);
}}
/>
<div>
<Switch
checked={discountSwitch}
onCheckedChange={(value) => {
setDiscountSwitch(value);
}}
/>
</div>
</div>
</div>
</div>

<div>
<Label>{_t("form.steps.summary.tax")}</Label>
)}

{!settings.taxPerItem.enabled && (
<div>
<Label>{_t("form.steps.summary.tax")}</Label>

<div>
<Switch
checked={taxSwitch}
onCheckedChange={(value) => {
setTaxSwitch(value);
}}
/>
<div>
<Switch
checked={taxSwitch}
onCheckedChange={(value) => {
setTaxSwitch(value);
}}
/>
</div>
</div>
</div>
</div>
)}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

<div>
<Label>{_t("form.steps.summary.shipping")}</Label>
Expand Down
Loading