Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invoice thing broke #549

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
81 changes: 39 additions & 42 deletions apps/web/src/components/invoice-generator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,20 @@
}

function InputRow({
placeholder,
label,
id,
name,
autoComplete,
type,
defaultValue,
multiple,
required,
step,
min,
onBeforeInput: onInput,
unit,
maxLength,
label,
name,
...restProps
}: GenericFieldProps) {
const htmlId = id ?? `inputfield.${name}`;

return (
<div>
<InputLabel name={label} htmlId={htmlId} />
<span className="flex">
<Input
id={htmlId}
name={name}
type={type ?? "text"}
placeholder={placeholder}
autoComplete={autoComplete}
defaultValue={defaultValue}
required={required}
multiple={multiple}
step={step}
min={min}
onBeforeInput={onInput}
maxLength={maxLength}
/>
{unit ? <span className="ml-2 translate-y-1">{unit}</span> : null}
<Input id={htmlId} type={type ?? "text"} name={name} {...restProps} />
{unit ? <span className="ml-1 translate-y-1">{unit}</span> : null}
</span>
</div>
);
Expand Down Expand Up @@ -239,6 +217,10 @@
}) {
const t = useScopedI18n("invoicegenerator");

const [quantity, setQuantity] = useState(0);
const [unitPrice, setUnitPrice] = useState(0);
const totalPrice = quantity * unitPrice;

return (
<fieldset>
<ErrorMessageBlock
Expand All @@ -254,7 +236,7 @@
/>
</ErrorMessageBlock>
<fieldset className="flex">
<span className="mr-0.5 grow">
<span className="mr-1 grow">
<ErrorMessageBlock
elementName={`rows[${index.toString()}].quantity`}
formState={state}
Expand All @@ -264,11 +246,12 @@
name="rows.quantity"
id={`rows[${index.toString()}].quantity`}
type="number"
onInput={(e) => setQuantity(Number(e.currentTarget.value))}

Check warning on line 249 in apps/web/src/components/invoice-generator/index.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Check types & Build

Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function
required
/>
</ErrorMessageBlock>
</span>
<span className="ml-0.5 grow">
<span className="ml-1 grow">
<ErrorMessageBlock
elementName={`rows[${index.toString()}].unit`}
formState={state}
Expand All @@ -284,23 +267,37 @@
</ErrorMessageBlock>
</span>
</fieldset>
<ErrorMessageBlock
elementName={`rows[${index.toString()}].unit_price`}
formState={state}
>
<span>
<fieldset className="flex">
<span className="mr-1 grow">
<ErrorMessageBlock
elementName={`rows[${index.toString()}].unit_price`}
formState={state}
>
<InputRow
label={t("Unit price")}
type="number"
name="rows.unit_price"
id={`rows[${index.toString()}].unit_price`}
onInput={(e) => setUnitPrice(Number(e.currentTarget.value))}

Check warning on line 281 in apps/web/src/components/invoice-generator/index.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Check types & Build

Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function
required
step={0.01}
min={0}
unit="€"
/>
</ErrorMessageBlock>
</span>
<span className="ml-1 grow">
<InputRow
label={t("Unit price")}
type="number"
name="rows.unit_price"
id={`rows[${index.toString()}].unit_price`}
required
step={0.01}
min={0}
label={t("Total price")}
type="text"
name="rows.total_price"
value={totalPrice.toFixed(2)}
id={`rows[${index.toString()}].total_price`}
unit="€"
disabled={true}

Check warning on line 297 in apps/web/src/components/invoice-generator/index.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Check types & Build

Value must be omitted for boolean attribute `disabled`
/>
</span>
</ErrorMessageBlock>
</fieldset>
</fieldset>
);
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const en = {
"invoicegenerator.Quantity": "Quantity",
"invoicegenerator.Unit": "Unit",
"invoicegenerator.Unit price": "Unit price",
"invoicegenerator.Total price": "Total price",
"invoicegenerator.Attachment": "Attachment",
"invoicegenerator.Attachments": "Attachments",
"invoicegenerator.Items": "Items",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/locales/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const fi = {
"invoicegenerator.Quantity": "Määrä",
"invoicegenerator.Unit": "Yksikkö",
"invoicegenerator.Unit price": "Yksikköhinta",
"invoicegenerator.Total price": "Yhteensä",
"invoicegenerator.Attachment": "Liite",
"invoicegenerator.Attachments": "Liitteet",
"invoicegenerator.Items": "Erittely",
Expand Down
Loading