@flowselections/e-mail-installatie-techniek 1.0.8 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/dist-lib/components/WerkbonPostvakInstelling.d.ts +2 -0
- package/dist-lib/components/WerkbonPostvakInstelling.d.ts.map +1 -0
- package/dist-lib/components/WerkbonPostvakInstelling.js +76 -0
- package/dist-lib/components/mail/CompetentiePicker.d.ts +9 -0
- package/dist-lib/components/mail/CompetentiePicker.d.ts.map +1 -0
- package/dist-lib/components/mail/CompetentiePicker.js +49 -0
- package/dist-lib/components/mail/MailPane.d.ts.map +1 -1
- package/dist-lib/components/mail/MailPane.js +13 -9
- package/dist-lib/components/mail/WerkbonProposalDialog.d.ts.map +1 -1
- package/dist-lib/components/mail/WerkbonProposalDialog.js +32 -4
- package/dist-lib/components/mail/WerkbonProposalForm.d.ts +3 -1
- package/dist-lib/components/mail/WerkbonProposalForm.d.ts.map +1 -1
- package/dist-lib/components/mail/WerkbonProposalForm.js +47 -21
- package/dist-lib/hooks/useAutoAnalyse.d.ts.map +1 -1
- package/dist-lib/hooks/useAutoAnalyse.js +36 -25
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +4 -0
- package/dist-lib/integrations/supabase/previewAuthStorage.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/previewAuthStorage.js +2 -1
- package/dist-lib/integrations/supabase/types.d.ts +14525 -392
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.js +1 -0
- package/dist-lib/lib/aantal-paginate.test.d.ts +2 -0
- package/dist-lib/lib/aantal-paginate.test.d.ts.map +1 -0
- package/dist-lib/lib/aantal-paginate.test.js +39 -0
- package/dist-lib/lib/aantal.d.ts +2 -0
- package/dist-lib/lib/aantal.d.ts.map +1 -0
- package/dist-lib/lib/aantal.js +10 -0
- package/dist-lib/lib/competenties.d.ts +12 -0
- package/dist-lib/lib/competenties.d.ts.map +1 -0
- package/dist-lib/lib/competenties.functions.d.ts +13 -0
- package/dist-lib/lib/competenties.functions.d.ts.map +1 -0
- package/dist-lib/lib/competenties.functions.js +22 -0
- package/dist-lib/lib/competenties.js +24 -0
- package/dist-lib/lib/competenties.test.d.ts +2 -0
- package/dist-lib/lib/competenties.test.d.ts.map +1 -0
- package/dist-lib/lib/competenties.test.js +15 -0
- package/dist-lib/lib/klant-match.d.ts +38 -0
- package/dist-lib/lib/klant-match.d.ts.map +1 -0
- package/dist-lib/lib/klant-match.js +88 -0
- package/dist-lib/lib/klant-match.test.d.ts +2 -0
- package/dist-lib/lib/klant-match.test.d.ts.map +1 -0
- package/dist-lib/lib/klant-match.test.js +76 -0
- package/dist-lib/lib/klanten.functions.d.ts.map +1 -1
- package/dist-lib/lib/klanten.functions.js +44 -51
- package/dist-lib/lib/paginate.d.ts +10 -0
- package/dist-lib/lib/paginate.d.ts.map +1 -0
- package/dist-lib/lib/paginate.js +18 -0
- package/dist-lib/lib/rekenregels-gelijk.test.d.ts +2 -0
- package/dist-lib/lib/rekenregels-gelijk.test.d.ts.map +1 -0
- package/dist-lib/lib/rekenregels-gelijk.test.js +63 -0
- package/dist-lib/lib/rekenregels.d.ts +44 -0
- package/dist-lib/lib/rekenregels.d.ts.map +1 -0
- package/dist-lib/lib/rekenregels.js +159 -0
- package/dist-lib/lib/rekenregels.test.d.ts +2 -0
- package/dist-lib/lib/rekenregels.test.d.ts.map +1 -0
- package/dist-lib/lib/rekenregels.test.js +74 -0
- package/dist-lib/lib/werkbon-approve-rows.d.ts +64 -0
- package/dist-lib/lib/werkbon-approve-rows.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-approve-rows.js +56 -0
- package/dist-lib/lib/werkbon-approve-rows.test.d.ts +2 -0
- package/dist-lib/lib/werkbon-approve-rows.test.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-approve-rows.test.js +103 -0
- package/dist-lib/lib/werkbon-postvak-settings.d.ts +15 -0
- package/dist-lib/lib/werkbon-postvak-settings.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-postvak-settings.functions.d.ts +14 -0
- package/dist-lib/lib/werkbon-postvak-settings.functions.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-postvak-settings.functions.js +24 -0
- package/dist-lib/lib/werkbon-postvak-settings.js +59 -0
- package/dist-lib/lib/werkbon-proposals.functions.d.ts +33 -0
- package/dist-lib/lib/werkbon-proposals.functions.d.ts.map +1 -1
- package/dist-lib/lib/werkbon-proposals.functions.js +100 -81
- package/package.json +131 -7
- package/supabase/werkbon-postvak-installatie.sql +758 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @flowselections/e-mail-installatie-techniek
|
|
2
|
+
|
|
3
|
+
Postvak Werkbonnen: aanvraagmails worden met AI omgezet in een werkbonvoorstel dat je aanpast, goedkeurt (werkbon aanmaken) of afwijst.
|
|
4
|
+
|
|
5
|
+
## Pagina's
|
|
6
|
+
- `WerkbonMailPage` – Voorstellen
|
|
7
|
+
- `WerkbonVerwerktPage` – Verwerkt
|
|
8
|
+
|
|
9
|
+
## Instellingenkaarten
|
|
10
|
+
- `EmailDoeleindeInstelling` – mailbox/doeleinde
|
|
11
|
+
- `MailAiInstructieInstelling` – AI-instructie en verplichte velden
|
|
12
|
+
- `WerkbonPostvakInstelling` – extra controles (tabel `werkbon_postvak_settings`, alles standaard uit = oud gedrag)
|
|
13
|
+
|
|
14
|
+
| Instelling | Standaard | Effect |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| optimistic_lock_enabled | uit | Weigert aanmaken als het voorstel intussen door een ander is gewijzigd |
|
|
17
|
+
| confirmation_require_valid_email | uit | Verstuurt geen orderbevestiging bij leeg/ongeldig adres |
|
|
18
|
+
| customer_match_in_db | uit | Klantherkenning via RPC `werkbon_match_customer_candidates` i.p.v. alle klanten ophalen |
|
|
19
|
+
| customer_match_fuzzy | uit | Ook pg_trgm-naamgelijkenis en e-maildomein (alleen bij één unieke klant) |
|
|
20
|
+
| customer_match_similarity | 0.6 | Grens voor naamgelijkenis |
|
|
21
|
+
| analyse_claim_ttl_seconds | 300 | Zo lang geldt de claim van één automatische AI-analyse |
|
|
22
|
+
| timezone | Europe/Amsterdam | Tijdzone voor de lokale datum |
|
|
23
|
+
| ai_local_date | uit | "Vandaag is" in de AI-instructie als lokale datum i.p.v. UTC |
|
|
24
|
+
|
|
25
|
+
## Database
|
|
26
|
+
- `werkbon_proposal_approve(...)` (SECURITY INVOKER): maakt werkbon, pakketregels, materialen en zet het voorstel op `approved` in één transactie; tweede aanroep geeft de bestaande werkbon terug.
|
|
27
|
+
- Unieke index `werkbon_proposals_created_werkbon_unique`.
|
|
28
|
+
- `werkbon_proposal_replace_lines(p_proposal_id, p_lines)` (SECURITY INVOKER): vervangt de voorstelregels in één transactie.
|
|
29
|
+
- `werkbon_proposal_claim_analyse(p_proposal_id, p_user, p_ttl_seconds, p_release)` (SECURITY INVOKER): één automatische analyse per mail tegelijk (kolommen `analyse_claimed_at`, `analyse_claimed_by`).
|
|
30
|
+
|
|
31
|
+
## Installatie in een nieuwe database
|
|
32
|
+
`supabase/werkbon-postvak-installatie.sql` (meegeleverd in het package) maakt alle eigen objecten van deze module aan: 9 tabellen met kolommen, constraints, indexen, rechten, RLS, policies, de updated_at-triggers, de 4 RPC's, de bucket `mail-inline` en de standaardrijen van de instellingen (`ON CONFLICT DO NOTHING`).
|
|
33
|
+
- Idempotent: `CREATE TABLE/INDEX IF NOT EXISTS`, `ADD COLUMN IF NOT EXISTS`, constraints/policies/triggers alleen als de naam nog niet bestaat (geen DROP), `CREATE OR REPLACE` voor de RPC's met de exacte huidige tekst.
|
|
34
|
+
- `update_updated_at_column` is gedeeld: alleen aangemaakt als hij ontbreekt, nooit vervangen.
|
|
35
|
+
- Ontbreekt een object van een andere module, dan volgt een `NOTICE` en wordt dat deel overgeslagen: FK naar `email_auth_events` (E-mail Authenticatie), policies met `has_role` (rollen), `werkbon_match_customer_candidates` (vereist `itk_customers`, `itk_contact_persons`). `werkbon_proposal_approve` is plpgsql en wordt altijd aangemaakt; `werkbonnen`, `werkbon_package_lines` en `werkbon_materials` (Pakketten Installatie Techniek) zijn pas bij aanroep nodig.
|
|
36
|
+
- Niet opgenomen (van de dashboardmodule): triggers `dashboard_funnel_capture` en `dashboard_tel_mailvoorstel` op `werkbon_proposals`.
|
|
37
|
+
|
|
38
|
+
### Testen in een lege database
|
|
39
|
+
Het script is niet op de huidige database gedraaid. Gecontroleerd is: syntaxis (pglast, 188 statements), dat het geen DROP/TRUNCATE/setval of URL's/sleutels/UUID's bevat (UPDATE/DELETE staan alleen in functie-inhoud en in `BEFORE UPDATE`/`FOR UPDATE`), en dat alle definities letterlijk uit `pg_get_functiondef`, `pg_get_triggerdef`, `pg_get_constraintdef`, `pg_policies` en `pg_indexes` komen.
|
|
40
|
+
Zo test je het in een nieuwe, lege Supabase-database:
|
|
41
|
+
1. Draai het script. Verwacht NOTICEs voor ontbrekende modules, geen fouten.
|
|
42
|
+
2. Draai het een tweede keer. Verwacht geen fouten.
|
|
43
|
+
3. Vergelijk na beide runs (moet gelijk zijn):
|
|
44
|
+
```sql
|
|
45
|
+
select (select count(*) from pg_tables where schemaname='public' and tablename like 'werkbon\_%') tabellen,
|
|
46
|
+
(select count(*) from pg_policies where schemaname='public' and tablename like 'werkbon\_%') policies,
|
|
47
|
+
(select count(*) from pg_trigger t join pg_class c on c.oid=t.tgrelid where not t.tgisinternal and c.relname like 'werkbon\_%') triggers,
|
|
48
|
+
(select count(*) from pg_proc where proname like 'werkbon\_%') functies,
|
|
49
|
+
(select count(*) from public.werkbon_postvak_settings) instellingenrijen;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Rekenregels
|
|
53
|
+
`src/lib/rekenregels.ts` bevat de gedeelde rekenregels (blok B). In deze module worden alleen `parseBedragNaarCenten` (budgetmandaat) en `vandaagLokaal` (AI-datum) gebruikt.
|
|
54
|
+
- `parseBedragNaarCenten` (1.3.0): negeert spaties, harde spaties en een euroteken vóór of achter ("€ 12,50" = "12,50 €" = 1250); "+5" = 500; "-0" en "-0,00" = 0; twee scheidingstekens naast elkaar of duizendtalgroepen die geen 3 cijfers hebben ("12,,50", "1.2.3", "1.23,45") = null.
|
|
55
|
+
- `pakketBedrag` (1.3.0): `kwartierMinuten` leeg of <= 0 → 15.
|
|
56
|
+
|
|
57
|
+
## Ontwikkelen
|
|
58
|
+
- `bun run test` – unittests (vitest)
|
|
59
|
+
- `npm run build:lib` – bibliotheek bouwen (niet zelf publiceren)
|
|
60
|
+
|
|
61
|
+
## Vereiste competenties (1.4.0)
|
|
62
|
+
Met de schakelaar "Vereiste competenties op werkbon" verschijnt onder Interne notities een meerkeuzemenu met de actieve competenties uit `uren_competenties` (module Urenregistratie). Het menu begint leeg en wordt nooit door de AI ingevuld. Bij goedkeuren zet `werkbon_proposal_approve` de keuze via `wo_set_vereiste_competenties` (werkbonmodule) in `werkbon_vereiste_competenties`; de planning controleert die met `wo_monteur_voldoet`. Ontbreken die tabellen of functies, dan wordt het overgeslagen.
|
|
63
|
+
|
|
64
|
+
## Later
|
|
65
|
+
- Reistijd eerst via Central Auth (zoals werkbonnen-monteur `rijtijdBron`), Lovable-gateway als terugval. Nu loopt de reistijd alleen via de Lovable-gateway.
|
|
66
|
+
|
|
67
|
+
## Omgevingswaarden
|
|
68
|
+
Geen nieuwe. Alles komt uit bestaande koppelingen en instellingentabellen.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WerkbonPostvakInstelling.d.ts","sourceRoot":"","sources":["../../src/components/WerkbonPostvakInstelling.tsx"],"names":[],"mappings":"AAwDA,wBAAgB,wBAAwB,gCA4GvC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
4
|
+
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Label, toast, } from "@flowselections/core";
|
|
5
|
+
import { ShieldCheck } from "lucide-react";
|
|
6
|
+
import { getPostvakSettings, savePostvakSettings, DEFAULT_POSTVAK_SETTINGS, } from "../lib/werkbon-postvak-settings.functions";
|
|
7
|
+
const TOGGLES = [
|
|
8
|
+
{
|
|
9
|
+
key: "optimistic_lock_enabled",
|
|
10
|
+
label: "Waarschuwen bij gelijktijdig bewerken",
|
|
11
|
+
help: "Heeft iemand anders het voorstel intussen gewijzigd, dan wordt er geen werkbon gemaakt.",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
key: "confirmation_require_valid_email",
|
|
15
|
+
label: "Orderbevestiging alleen naar een geldig adres",
|
|
16
|
+
help: "Bij een leeg of ongeldig adres wordt de bevestiging niet verstuurd.",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
key: "customer_match_in_db",
|
|
20
|
+
label: "Klant herkennen in de database",
|
|
21
|
+
help: "Zoekt alleen de passende klanten op in plaats van het hele klantenbestand.",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: "customer_match_fuzzy",
|
|
25
|
+
label: "Ruime klantherkenning",
|
|
26
|
+
help: "Herkent ook een klant met een bijna gelijke naam of hetzelfde e-maildomein. Werkt alleen samen met de vorige optie.",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "ai_local_date",
|
|
30
|
+
label: "Lokale datum voor de AI",
|
|
31
|
+
help: "De AI krijgt de datum van vandaag in de tijdzone hieronder in plaats van de UTC-datum.",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: "competenties_enabled",
|
|
35
|
+
label: "Vereiste competenties op werkbon",
|
|
36
|
+
help: "Toont een keuzemenu met competenties uit Urenregistratie. De planning laat de werkbon dan alleen toe bij een monteur met al die competenties.",
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
export function WerkbonPostvakInstelling() {
|
|
40
|
+
const load = useServerFn(getPostvakSettings);
|
|
41
|
+
const save = useServerFn(savePostvakSettings);
|
|
42
|
+
const [value, setValue] = useState(DEFAULT_POSTVAK_SETTINGS);
|
|
43
|
+
const [loading, setLoading] = useState(true);
|
|
44
|
+
const [saving, setSaving] = useState(false);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
let alive = true;
|
|
47
|
+
load({})
|
|
48
|
+
.then((s) => alive && s && setValue(s))
|
|
49
|
+
.catch((e) => {
|
|
50
|
+
console.error(e);
|
|
51
|
+
toast.error(e instanceof Error ? e.message : "Instellingen laden is mislukt.");
|
|
52
|
+
})
|
|
53
|
+
.finally(() => alive && setLoading(false));
|
|
54
|
+
return () => {
|
|
55
|
+
alive = false;
|
|
56
|
+
};
|
|
57
|
+
}, [load]);
|
|
58
|
+
const onSave = async () => {
|
|
59
|
+
setSaving(true);
|
|
60
|
+
try {
|
|
61
|
+
const next = await save({ data: value });
|
|
62
|
+
if (next)
|
|
63
|
+
setValue(next);
|
|
64
|
+
toast.success("Instellingen opgeslagen");
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.error(e);
|
|
68
|
+
toast.error(e instanceof Error ? e.message : "Opslaan is mislukt.");
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
setSaving(false);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const busy = loading || saving;
|
|
75
|
+
return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsxs("div", { className: "flex items-start gap-3", children: [_jsx(ShieldCheck, { className: "mt-1 h-5 w-5 text-primary" }), _jsxs("div", { children: [_jsx(CardTitle, { children: "Werkbonvoorstellen" }), _jsx(CardDescription, { children: "Extra controles. Staat alles uit, dan werkt alles zoals altijd." })] })] }) }), _jsxs(CardContent, { className: "space-y-4", children: [TOGGLES.map((t) => (_jsxs("label", { className: "flex items-start gap-2 text-sm", children: [_jsx("input", { type: "checkbox", className: "mt-0.5 h-4 w-4 accent-[var(--primary)]", checked: value[t.key], disabled: busy, onChange: (e) => setValue((v) => ({ ...v, [t.key]: e.target.checked })) }), _jsxs("span", { children: [_jsx("span", { className: "font-medium", children: t.label }), _jsx("span", { className: "block text-xs text-muted-foreground", children: t.help })] })] }, t.key))), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "postvak-sim", children: "Gelijkenisgrens voor namen (0,1 \u2013 1,0)" }), _jsx(Input, { id: "postvak-sim", type: "number", step: "0.05", min: "0.1", max: "1", className: "w-32", value: value.customer_match_similarity, disabled: busy || !value.customer_match_fuzzy, onChange: (e) => setValue((v) => ({ ...v, customer_match_similarity: Number(e.target.value) })) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "postvak-tz", children: "Tijdzone" }), _jsx(Input, { id: "postvak-tz", className: "w-64", value: value.timezone, disabled: busy, onChange: (e) => setValue((v) => ({ ...v, timezone: e.target.value })) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "postvak-ttl", children: "Maximale duur van een AI-analyse (seconden)" }), _jsx(Input, { id: "postvak-ttl", type: "number", min: "10", step: "10", className: "w-32", value: value.analyse_claim_ttl_seconds, disabled: busy, onChange: (e) => setValue((v) => ({ ...v, analyse_claim_ttl_seconds: Number(e.target.value) })) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Zolang een mail wordt geanalyseerd, slaan andere open schermen hem over." })] }), _jsx(Button, { onClick: onSave, disabled: busy, children: "Opslaan" })] })] }));
|
|
76
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
value: string[];
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
onChange: (ids: string[]) => void;
|
|
5
|
+
}
|
|
6
|
+
/** Meerkeuze uit de competenties van Urenregistratie. Begint leeg; vult niets automatisch in. */
|
|
7
|
+
export declare function CompetentiePicker({ value, disabled, onChange }: Props): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=CompetentiePicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompetentiePicker.d.ts","sourceRoot":"","sources":["../../../src/components/mail/CompetentiePicker.tsx"],"names":[],"mappings":"AAOA,UAAU,KAAK;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACnC;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,KAAK,+BAoFrE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { ChevronsUpDown, X } from "lucide-react";
|
|
4
|
+
import { Button, Checkbox, Popover, PopoverContent, PopoverTrigger } from "@flowselections/core";
|
|
5
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
6
|
+
import { toast } from "sonner";
|
|
7
|
+
import { getCompetenties } from "../../lib/competenties.functions";
|
|
8
|
+
/** Meerkeuze uit de competenties van Urenregistratie. Begint leeg; vult niets automatisch in. */
|
|
9
|
+
export function CompetentiePicker({ value, disabled, onChange }) {
|
|
10
|
+
const load = useServerFn(getCompetenties);
|
|
11
|
+
const [items, setItems] = useState([]);
|
|
12
|
+
const [available, setAvailable] = useState(true);
|
|
13
|
+
const [loading, setLoading] = useState(true);
|
|
14
|
+
const [open, setOpen] = useState(false);
|
|
15
|
+
const selected = Array.isArray(value) ? value : [];
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
let alive = true;
|
|
18
|
+
load()
|
|
19
|
+
.then((res) => {
|
|
20
|
+
if (!alive)
|
|
21
|
+
return;
|
|
22
|
+
setItems(Array.isArray(res?.items) ? res.items : []);
|
|
23
|
+
setAvailable(Boolean(res?.available));
|
|
24
|
+
if (res?.error)
|
|
25
|
+
toast.error(`Competenties laden mislukt: ${res.error}`);
|
|
26
|
+
})
|
|
27
|
+
.catch((e) => {
|
|
28
|
+
console.error("getCompetenties failed", e);
|
|
29
|
+
if (alive)
|
|
30
|
+
toast.error("Competenties laden mislukt.");
|
|
31
|
+
})
|
|
32
|
+
.finally(() => alive && setLoading(false));
|
|
33
|
+
return () => {
|
|
34
|
+
alive = false;
|
|
35
|
+
};
|
|
36
|
+
}, [load]);
|
|
37
|
+
const byId = useMemo(() => new Map(items.map((c) => [c.id, c])), [items]);
|
|
38
|
+
const groups = useMemo(() => {
|
|
39
|
+
const m = new Map();
|
|
40
|
+
for (const c of items)
|
|
41
|
+
(m.get(c.categorie) ?? m.set(c.categorie, []).get(c.categorie)).push(c);
|
|
42
|
+
return [...m.entries()];
|
|
43
|
+
}, [items]);
|
|
44
|
+
const toggle = (id) => onChange(selected.includes(id) ? selected.filter((v) => v !== id) : [...selected, id]);
|
|
45
|
+
if (!loading && !available) {
|
|
46
|
+
return _jsx("p", { className: "text-sm text-muted-foreground", children: "Competenties niet beschikbaar." });
|
|
47
|
+
}
|
|
48
|
+
return (_jsxs("div", { className: "space-y-2", children: [_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "outline", className: "w-full justify-between", disabled: disabled || loading, children: [_jsx("span", { className: "truncate", children: loading ? "Laden…" : selected.length ? `${selected.length} gekozen` : "Kies competenties…" }), _jsx(ChevronsUpDown, { className: "h-4 w-4 opacity-50" })] }) }), _jsxs(PopoverContent, { className: "max-h-80 w-[--radix-popover-trigger-width] overflow-y-auto p-2", align: "start", children: [groups.length === 0 && _jsx("p", { className: "p-2 text-sm text-muted-foreground", children: "Geen competenties gevonden." }), groups.map(([cat, list]) => (_jsxs("div", { className: "mb-2", children: [_jsx("p", { className: "px-2 py-1 text-xs font-semibold text-muted-foreground", children: cat }), list.map((c) => (_jsxs("label", { className: "flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent", children: [_jsx(Checkbox, { checked: selected.includes(c.id), onCheckedChange: () => toggle(c.id) }), c.naam] }, c.id)))] }, cat)))] })] }), selected.length > 0 && (_jsx("div", { className: "flex flex-wrap gap-1.5", children: selected.map((id) => (_jsxs("span", { className: "inline-flex items-center gap-1 rounded-full bg-secondary px-2 py-0.5 text-xs text-secondary-foreground", children: [byId.get(id)?.naam ?? "Onbekende competentie", !disabled && (_jsx("button", { type: "button", "aria-label": "Verwijderen", onClick: () => toggle(id), children: _jsx(X, { className: "h-3 w-3" }) }))] }, id))) })), _jsx("p", { className: "text-xs text-muted-foreground", children: "Alleen een monteur met al deze competenties kan de werkbon in de planning krijgen." })] }));
|
|
49
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailPane.d.ts","sourceRoot":"","sources":["../../../src/components/mail/MailPane.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAK5E,UAAU,KAAK;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CAC7C;AAkBD,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAe,EAAE,eAAe,EAAE,EAAE,KAAK,+
|
|
1
|
+
{"version":3,"file":"MailPane.d.ts","sourceRoot":"","sources":["../../../src/components/mail/MailPane.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAK5E,UAAU,KAAK;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CAC7C;AAkBD,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAe,EAAE,eAAe,EAAE,EAAE,KAAK,+BA8OzE"}
|
|
@@ -12,7 +12,7 @@ const HEAD_KEY = "werkbon-mail:kop";
|
|
|
12
12
|
// achtergrond en geen horizontale schuifbalk — de schaal wordt na het laden
|
|
13
13
|
// door de app op de body gezet zodat de mail volledig in het paneel past.
|
|
14
14
|
function emailDocument(body) {
|
|
15
|
-
return `<!doctype html><html><head><meta charset="utf-8"><style>html{background:#fff;overflow-x:hidden}body{margin:0;padding:12px;background:#fff}img{max-width:100%;height:auto}</style></head><body>${body}</body></html>`;
|
|
15
|
+
return `<!doctype html><html><head><meta charset="utf-8"><style>html{background:#fff;overflow-x:hidden}body{margin:0;padding:12px;background:#fff;overflow-wrap:anywhere;word-break:break-word}body>*{margin-left:auto!important;margin-right:auto!important}pre,code{white-space:pre-wrap!important;overflow-wrap:anywhere}table{max-width:100%}td,th{overflow-wrap:anywhere}img{max-width:100%;height:auto}</style></head><body>${body}</body></html>`;
|
|
16
16
|
}
|
|
17
17
|
function readNumber(key, fallback) {
|
|
18
18
|
if (typeof window === "undefined")
|
|
@@ -66,6 +66,7 @@ export function MailPane({ mail, loading = false, onToggleArchive }) {
|
|
|
66
66
|
const iframeRef = useRef(null);
|
|
67
67
|
// De mail altijd volledig in het paneel passen: schaal bij totdat de inhoud
|
|
68
68
|
// binnen de beschikbare breedte past, zodat je nooit horizontaal schuift.
|
|
69
|
+
const applyFitScaleRef = useRef(() => { });
|
|
69
70
|
const applyFitScale = useCallback(() => {
|
|
70
71
|
const frame = iframeRef.current;
|
|
71
72
|
if (!frame)
|
|
@@ -82,16 +83,19 @@ export function MailPane({ mail, loading = false, onToggleArchive }) {
|
|
|
82
83
|
const avail = frame.clientWidth;
|
|
83
84
|
if (avail <= 0)
|
|
84
85
|
return;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
// Eén keer meten op ware grootte; zoom komt bovenop de passende schaal.
|
|
87
|
+
doc.body.style.zoom = "1";
|
|
88
|
+
const natural = Math.max(doc.documentElement.scrollWidth, doc.body.scrollWidth, 1);
|
|
89
|
+
const fit = Math.max(0.5, Math.min(1, avail / natural));
|
|
90
|
+
const scale = fit * (zoom / 100);
|
|
91
|
+
doc.body.style.zoom = String(scale);
|
|
92
|
+
doc.documentElement.style.overflowX = scale <= fit + 0.001 ? "hidden" : "auto";
|
|
93
|
+
if (!doc.__fitImgHook) {
|
|
94
|
+
doc.__fitImgHook = true;
|
|
95
|
+
doc.addEventListener("load", () => applyFitScaleRef.current(), true);
|
|
92
96
|
}
|
|
93
|
-
doc.documentElement.style.overflowX = "hidden";
|
|
94
97
|
}, [zoom]);
|
|
98
|
+
applyFitScaleRef.current = applyFitScale;
|
|
95
99
|
useEffect(() => {
|
|
96
100
|
applyFitScale();
|
|
97
101
|
}, [applyFitScale]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WerkbonProposalDialog.d.ts","sourceRoot":"","sources":["../../../src/components/mail/WerkbonProposalDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"WerkbonProposalDialog.d.ts","sourceRoot":"","sources":["../../../src/components/mail/WerkbonProposalDialog.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA6B5D,UAAU,KAAK;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,eAAe,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA2ED,wBAAgB,qBAAqB,CAAC,EACpC,IAAI,EACJ,WAAmB,EACnB,OAAO,EACP,eAAe,EACf,OAAO,EACP,MAAa,EACb,MAAa,EACb,aAAoB,EACpB,QAAgB,GACjB,EAAE,KAAK,+BAmdP"}
|
|
@@ -7,6 +7,8 @@ import { sendMailForPurpose } from "@flowselections/e-mail-authenticatie-module"
|
|
|
7
7
|
import { analyseWerkbonMail, prepareWerkbonAnalyse, approveWerkbonProposal, getWerkbonProposalForMail, listWerkbonOptions, markWerkbonConfirmationSent, getConfirmationDelivery, rejectWerkbonProposal, saveWerkbonProposal, } from "../../lib/werkbon-proposals.functions";
|
|
8
8
|
import { buildConfirmationMail, extractEmail } from "../../lib/werkbon-confirmation-mail";
|
|
9
9
|
import { useEmailPurpose } from "../../hooks/useEmailPurpose";
|
|
10
|
+
import { isValidEmail } from "../../lib/werkbon-approve-rows";
|
|
11
|
+
import { getPostvakSettings, DEFAULT_POSTVAK_SETTINGS, } from "../../lib/werkbon-postvak-settings.functions";
|
|
10
12
|
import { runAiChat } from "@flowselections/ai-authenticatie";
|
|
11
13
|
import { matchKlantForMail } from "../../lib/klanten.functions";
|
|
12
14
|
import { NieuweKlantDialog } from "../klanten/NieuweKlantDialog";
|
|
@@ -31,6 +33,7 @@ function toForm(p) {
|
|
|
31
33
|
externe_referentie: p.externe_referentie,
|
|
32
34
|
budget_mandate_cents: p.budget_mandate_cents,
|
|
33
35
|
internal_notes: p.internal_notes,
|
|
36
|
+
vereiste_competentie_ids: Array.isArray(p.vereiste_competentie_ids) ? p.vereiste_competentie_ids : [],
|
|
34
37
|
lines: (Array.isArray(p.lines) ? p.lines : []).map((l) => l.line_type === "package" && l.quantity == null ? { ...l, quantity: 1 } : l),
|
|
35
38
|
};
|
|
36
39
|
}
|
|
@@ -91,6 +94,17 @@ export function WerkbonProposalDialog({ mail, mailLoading = false, onClose, onTo
|
|
|
91
94
|
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
92
95
|
const [sendConfirmation, setSendConfirmation] = useState(true);
|
|
93
96
|
const [sendTo, setSendTo] = useState("");
|
|
97
|
+
const loadSettings = useServerFn(getPostvakSettings);
|
|
98
|
+
const [settings, setSettings] = useState(DEFAULT_POSTVAK_SETTINGS);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
let alive = true;
|
|
101
|
+
loadSettings({})
|
|
102
|
+
.then((s) => alive && s && setSettings(s))
|
|
103
|
+
.catch((e) => console.error("Postvak-instellingen laden mislukt", e));
|
|
104
|
+
return () => {
|
|
105
|
+
alive = false;
|
|
106
|
+
};
|
|
107
|
+
}, [loadSettings]);
|
|
94
108
|
const [options, setOptions] = useState(EMPTY_OPTIONS);
|
|
95
109
|
const [proposal, setProposal] = useState(null);
|
|
96
110
|
const [form, setForm] = useState(null);
|
|
@@ -261,6 +275,8 @@ export function WerkbonProposalDialog({ mail, mailLoading = false, onClose, onTo
|
|
|
261
275
|
budget_mandate_cents: value.budget_mandate_cents,
|
|
262
276
|
internal_notes: value.internal_notes,
|
|
263
277
|
lines: value.lines,
|
|
278
|
+
expected_updated_at: settings.optimistic_lock_enabled ? (proposal?.updated_at ?? null) : null,
|
|
279
|
+
...(settings.competenties_enabled ? { vereiste_competentie_ids: value.vereiste_competentie_ids ?? [] } : {}),
|
|
264
280
|
});
|
|
265
281
|
const confirmWerkbon = async () => {
|
|
266
282
|
if (!proposal || !form)
|
|
@@ -277,8 +293,18 @@ export function WerkbonProposalDialog({ mail, mailLoading = false, onClose, onTo
|
|
|
277
293
|
}
|
|
278
294
|
const nr = res?.project_number ?? "";
|
|
279
295
|
const label = nr ? `Werkbon ${nr} aangemaakt` : "Werkbon aangemaakt";
|
|
280
|
-
const
|
|
281
|
-
|
|
296
|
+
const extracted = extractEmail(sendTo);
|
|
297
|
+
const to = settings.confirmation_require_valid_email && extracted && !isValidEmail(extracted) ? null : extracted;
|
|
298
|
+
if (sendConfirmation && !to && settings.confirmation_require_valid_email) {
|
|
299
|
+
toast.error(`${label}, maar de orderbevestiging is niet verstuurd: er is geen geldig e-mailadres ingevuld.`);
|
|
300
|
+
try {
|
|
301
|
+
await markSent({ data: { proposal_id: proposal.id, to: null, error: "Geen geldig e-mailadres" } });
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
console.error("Vastleggen orderbevestiging mislukt", e);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else if (sendConfirmation && to) {
|
|
282
308
|
let sendError = null;
|
|
283
309
|
try {
|
|
284
310
|
if (!purpose)
|
|
@@ -350,13 +376,15 @@ export function WerkbonProposalDialog({ mail, mailLoading = false, onClose, onTo
|
|
|
350
376
|
setSendTo(extractEmail(mail.from));
|
|
351
377
|
setSendConfirmation(true);
|
|
352
378
|
setConfirmOpen(true);
|
|
353
|
-
}, onReject: rejectProposal, onNewCustomer: () => setNewKlantOpen(true), readOnly: readOnly }) })), readOnly && proposal && (proposal.confirmation_sent_at || proposal.confirmation_error) && (_jsx("div", { className: "shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground", children: proposal.confirmation_sent_at ? (_jsxs(_Fragment, { children: [_jsx("p", { children: `Orderbevestiging aangeboden voor ${proposal.confirmation_to ?? "klant"} op ${new Date(proposal.confirmation_sent_at).toLocaleString("nl-NL")}` }), _jsx("p", { className: delivery?.last_error || delivery?.status === "failed" ? "text-destructive" : undefined, children: !delivery
|
|
379
|
+
}, onReject: rejectProposal, onNewCustomer: () => setNewKlantOpen(true), readOnly: readOnly, showCompetenties: settings.competenties_enabled }) })), readOnly && proposal && (proposal.confirmation_sent_at || proposal.confirmation_error) && (_jsx("div", { className: "shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground", children: proposal.confirmation_sent_at ? (_jsxs(_Fragment, { children: [_jsx("p", { children: `Orderbevestiging aangeboden voor ${proposal.confirmation_to ?? "klant"} op ${new Date(proposal.confirmation_sent_at).toLocaleString("nl-NL")}` }), _jsx("p", { className: delivery?.last_error || delivery?.status === "failed" ? "text-destructive" : undefined, children: !delivery
|
|
354
380
|
? "Verzendstatus mailserver: onbekend"
|
|
355
381
|
: delivery.sent_at
|
|
356
382
|
? `Verstuurd door mailserver op ${new Date(delivery.sent_at).toLocaleString("nl-NL")}`
|
|
357
383
|
: delivery.last_error
|
|
358
384
|
? `Mailserver-fout: ${delivery.last_error}`
|
|
359
|
-
: `Verzendstatus mailserver: ${delivery.status ?? "in wachtrij"}` })] })) : (_jsx("p", { children: `Orderbevestiging niet verstuurd: ${proposal.confirmation_error}` })) }))] })] })] }), confirmOpen && (_jsx("div", { className: "fixed inset-0 z-[200] flex items-center justify-center bg-foreground/40 p-4", onClick: () => !saving && setConfirmOpen(false), children: _jsxs("div", { className: "w-full max-w-md space-y-4 rounded-lg border border-border bg-card p-5 shadow-lg", onClick: (e) => e.stopPropagation(), children: [_jsx("h3", { className: "text-base font-semibold", children: "Werkbon aanmaken" }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: sendConfirmation, onChange: (e) => setSendConfirmation(e.target.checked) }), "Orderbevestiging naar klant sturen"] }), sendConfirmation && (_jsxs("div", { className: "space-y-1", children: [_jsx("
|
|
385
|
+
: `Verzendstatus mailserver: ${delivery.status ?? "in wachtrij"}` })] })) : (_jsx("p", { children: `Orderbevestiging niet verstuurd: ${proposal.confirmation_error}` })) }))] })] })] }), confirmOpen && (_jsx("div", { className: "fixed inset-0 z-[200] flex items-center justify-center bg-foreground/40 p-4", onClick: () => !saving && setConfirmOpen(false), children: _jsxs("div", { className: "w-full max-w-md space-y-4 rounded-lg border border-border bg-card p-5 shadow-lg", onClick: (e) => e.stopPropagation(), children: [_jsx("h3", { className: "text-base font-semibold", children: "Werkbon aanmaken" }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: sendConfirmation, onChange: (e) => setSendConfirmation(e.target.checked) }), "Orderbevestiging naar klant sturen"] }), sendConfirmation && (_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm", children: extractEmail(sendTo)
|
|
386
|
+
? _jsxs(_Fragment, { children: ["De bevestiging gaat naar: ", _jsx("strong", { children: extractEmail(sendTo) })] })
|
|
387
|
+
: _jsx("span", { className: "text-destructive", children: "Vul een geldig e-mailadres in om de bevestiging te versturen." }) }), _jsx("label", { className: "text-xs text-muted-foreground", children: "E-mailadres klant" }), _jsx(Input, { type: "email", value: sendTo, onChange: (e) => setSendTo(e.target.value), placeholder: "naam@voorbeeld.nl" })] })), _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { variant: "outline", disabled: saving, onClick: () => setConfirmOpen(false), children: "Annuleren" }), _jsx(Button, { disabled: saving || (sendConfirmation && !extractEmail(sendTo)), onClick: confirmWerkbon, children: "Werkbon aanmaken" })] })] }) })), _jsx(NieuweKlantDialog, { open: newKlantOpen, onOpenChange: setNewKlantOpen, defaults: newKlantOpen ? buildKlantDefaults(mail, proposal, form?.work_address ?? proposal?.work_address) : null, onCreated: (klant) => {
|
|
360
388
|
setForm((prev) => (prev ? { ...prev, customer_id: klant.id } : prev));
|
|
361
389
|
void reloadOptions();
|
|
362
390
|
} })] }));
|
|
@@ -12,6 +12,7 @@ export interface WerkbonFormValue {
|
|
|
12
12
|
externe_referentie: string | null;
|
|
13
13
|
budget_mandate_cents: number | null;
|
|
14
14
|
internal_notes: string | null;
|
|
15
|
+
vereiste_competentie_ids?: string[];
|
|
15
16
|
lines: WerkbonLine[];
|
|
16
17
|
}
|
|
17
18
|
interface Props {
|
|
@@ -24,7 +25,8 @@ interface Props {
|
|
|
24
25
|
onReject: () => void;
|
|
25
26
|
onNewCustomer: () => void;
|
|
26
27
|
readOnly?: boolean;
|
|
28
|
+
showCompetenties?: boolean;
|
|
27
29
|
}
|
|
28
|
-
export declare function WerkbonProposalForm({ value, options, saving, analysing, onChange, onConfirm, onReject, onNewCustomer, readOnly, }: Props): import("react").JSX.Element;
|
|
30
|
+
export declare function WerkbonProposalForm({ value, options, saving, analysing, onChange, onConfirm, onReject, onNewCustomer, readOnly, showCompetenties, }: Props): import("react").JSX.Element;
|
|
29
31
|
export {};
|
|
30
32
|
//# sourceMappingURL=WerkbonProposalForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WerkbonProposalForm.d.ts","sourceRoot":"","sources":["../../../src/components/mail/WerkbonProposalForm.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WerkbonProposalForm.d.ts","sourceRoot":"","sources":["../../../src/components/mail/WerkbonProposalForm.tsx"],"names":[],"mappings":"AAcA,OAAO,EAQL,KAAK,WAAW,EAChB,KAAK,cAAc,EAEpB,MAAM,uCAAuC,CAAC;AAI/C,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,2BAA2B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,0BAA0B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;IACpC,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAED,UAAU,KAAK;IACb,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACrD,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AA4cD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,OAAO,EACP,MAAM,EACN,SAAiB,EACjB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAgB,EAChB,gBAAwB,GACzB,EAAE,KAAK,+BA+pBP"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { parseBedragNaarCenten } from "../../lib/rekenregels";
|
|
4
|
+
import { parseAantal } from "../../lib/aantal";
|
|
3
5
|
import { Check, ChevronsUpDown, Plus, Search, Trash2, UserPlus } from "lucide-react";
|
|
4
6
|
import { Button, Input, Label, Popover, PopoverContent, PopoverTrigger, Textarea, } from "@flowselections/core";
|
|
5
7
|
import { useServerFn } from "@tanstack/react-start";
|
|
6
8
|
import { computeWerkbonTravel, getWerkbonLinesTotal, formatEuroCents, searchArtikelen, getArtikelFotos, } from "../../lib/werkbon-proposals.functions";
|
|
7
9
|
import { getKlantStatus } from "../../lib/klanten.functions";
|
|
10
|
+
import { CompetentiePicker } from "./CompetentiePicker";
|
|
8
11
|
function Section({ title, children }) {
|
|
9
12
|
return (_jsxs("section", { className: "space-y-3 rounded-md border border-border p-4", children: [_jsx("h3", { className: "text-sm font-semibold", children: title }), children] }));
|
|
10
13
|
}
|
|
@@ -182,8 +185,21 @@ function toDateInput(value) {
|
|
|
182
185
|
const d = new Date(value);
|
|
183
186
|
return Number.isNaN(d.getTime()) ? "" : d.toISOString().slice(0, 10);
|
|
184
187
|
}
|
|
185
|
-
export function WerkbonProposalForm({ value, options, saving, analysing = false, onChange, onConfirm, onReject, onNewCustomer, readOnly = false, }) {
|
|
188
|
+
export function WerkbonProposalForm({ value, options, saving, analysing = false, onChange, onConfirm, onReject, onNewCustomer, readOnly = false, showCompetenties = false, }) {
|
|
186
189
|
const lines = Array.isArray(value.lines) ? value.lines : [];
|
|
190
|
+
const [invalidFields, setInvalidFields] = useState(() => new Set());
|
|
191
|
+
const markInvalid = useCallback((key, bad) => {
|
|
192
|
+
setInvalidFields((prev) => {
|
|
193
|
+
if (prev.has(key) === bad)
|
|
194
|
+
return prev;
|
|
195
|
+
const next = new Set(prev);
|
|
196
|
+
if (bad)
|
|
197
|
+
next.add(key);
|
|
198
|
+
else
|
|
199
|
+
next.delete(key);
|
|
200
|
+
return next;
|
|
201
|
+
});
|
|
202
|
+
}, []);
|
|
187
203
|
// Totaal van pakketten + materialen t.o.v. het mandaat (prijzen uit de database).
|
|
188
204
|
const fetchTotal = useServerFn(getWerkbonLinesTotal);
|
|
189
205
|
const [totalCents, setTotalCents] = useState(null);
|
|
@@ -432,19 +448,11 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
432
448
|
}, [materialCodesKey]);
|
|
433
449
|
return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "min-h-0 flex-1 space-y-4 overflow-y-auto p-5", children: [_jsx("h2", { className: "text-base font-semibold", children: "Werkbonvoorstel" }), (klantRisk || klantBlocked) && (_jsxs("div", { role: "alert", className: `rounded-md border p-3 text-sm ${klantBlocked
|
|
434
450
|
? "border-destructive/50 bg-destructive/10 text-destructive"
|
|
435
|
-
: "border-orange-400/60 bg-orange-500/10 text-orange-700 dark:text-orange-300"}`, children: [_jsx("p", { className: "font-semibold", children: klantBlocked ? "Deze klant is geblokkeerd" : "Let op: dit is een risicoklant" }), klantNotes.length > 0 && (_jsx("ul", { className: "mt-1 list-disc space-y-0.5 pl-5", children: klantNotes.map((n, i) => (_jsx("li", { children: n }, i))) }))] })), _jsxs(Section, { title: "Klant & locatie", children: [_jsxs(Field, { label: "Klant", required: true, empty: !value.customer_id, children: [_jsx(CustomerPicker, { customers: Array.isArray(options.customers) ? options.customers : [], value: value.customer_id, onSelect: (id) => onChange({ customer_id: id }), onClear: () => onChange({ customer_id: null }), onNewCustomer: onNewCustomer }), !value.customer_id && !readOnly && (_jsxs("div", { className: "mt-1.5 flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-xs font-medium text-destructive", children: "Klant niet bekend" }), _jsxs(Button, { type: "button", size: "sm", variant: "outline", className: "gap-1.5", onClick: onNewCustomer, children: [_jsx(UserPlus, { className: "h-3.5 w-3.5" }), "Nieuwe klant toevoegen"] })] }))] }), _jsx(Field, { label: "Werkadres", children: _jsx(Input, { value: value.work_address ?? "", placeholder: "Straat, postcode, plaats", onChange: (e) => onChange({ work_address: e.target.value || null }) }) }), _jsx(Field, { label: "kamer/ruimte nummer", children: _jsx(Input, { value: value.room_number ?? "", placeholder: "Bijv. 2.14", onChange: (e) => onChange({ room_number: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Project & referentie", children: [_jsx(Field, { label: "Externe referentie", children: _jsx(Input, { value: value.externe_referentie ?? "", placeholder: "Referentie van de klant", onChange: (e) => onChange({ externe_referentie: e.target.value || null }) }) }), _jsxs(Field, { label: "Budgetmandaat (\u20AC)", children: [_jsx(
|
|
436
|
-
|
|
437
|
-
onChange({
|
|
438
|
-
budget_mandate_cents: e.target.value === "" || Number.isNaN(n) ? null : Math.round(n * 100),
|
|
439
|
-
});
|
|
440
|
-
} }), mandateCents > 0 && (_jsx(MandaatBalk, { totalCents: totalCents ?? 0, mandateCents: mandateCents }))] })] }), _jsxs(Section, { title: "Opdracht", children: [_jsx(Field, { label: "Klacht / melding", children: _jsx(Textarea, { rows: 4, value: value.complaint_description ?? "", placeholder: "Wat is er aan de hand?", onChange: (e) => onChange({ complaint_description: e.target.value || null }) }) }), _jsx(Field, { label: "Omschrijving voor de monteur", children: _jsx(Textarea, { rows: 4, value: value.technician_task_description ?? "", placeholder: "Wat moet er gebeuren?", onChange: (e) => onChange({ technician_task_description: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Pakketten toevoegen", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Werkzaamheden" }), packageLines.length === 0 && (_jsx("p", { className: "text-xs text-muted-foreground", children: "Nog geen werkzaamheden." })), !readOnly && travel && (_jsx("p", { className: travel.error ? "text-xs text-destructive" : "text-xs text-muted-foreground", children: travel.error
|
|
451
|
+
: "border-orange-400/60 bg-orange-500/10 text-orange-700 dark:text-orange-300"}`, children: [_jsx("p", { className: "font-semibold", children: klantBlocked ? "Deze klant is geblokkeerd" : "Let op: dit is een risicoklant" }), klantNotes.length > 0 && (_jsx("ul", { className: "mt-1 list-disc space-y-0.5 pl-5", children: klantNotes.map((n, i) => (_jsx("li", { children: n }, i))) }))] })), _jsxs(Section, { title: "Klant & locatie", children: [_jsxs(Field, { label: "Klant", required: true, empty: !value.customer_id, children: [_jsx(CustomerPicker, { customers: Array.isArray(options.customers) ? options.customers : [], value: value.customer_id, onSelect: (id) => onChange({ customer_id: id }), onClear: () => onChange({ customer_id: null }), onNewCustomer: onNewCustomer }), !value.customer_id && !readOnly && (_jsxs("div", { className: "mt-1.5 flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-xs font-medium text-destructive", children: "Klant niet bekend" }), _jsxs(Button, { type: "button", size: "sm", variant: "outline", className: "gap-1.5", onClick: onNewCustomer, children: [_jsx(UserPlus, { className: "h-3.5 w-3.5" }), "Nieuwe klant toevoegen"] })] }))] }), _jsx(Field, { label: "Werkadres", children: _jsx(Input, { value: value.work_address ?? "", placeholder: "Straat, postcode, plaats", onChange: (e) => onChange({ work_address: e.target.value || null }) }) }), _jsx(Field, { label: "kamer/ruimte nummer", children: _jsx(Input, { value: value.room_number ?? "", placeholder: "Bijv. 2.14", onChange: (e) => onChange({ room_number: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Project & referentie", children: [_jsx(Field, { label: "Externe referentie", children: _jsx(Input, { value: value.externe_referentie ?? "", placeholder: "Referentie van de klant", onChange: (e) => onChange({ externe_referentie: e.target.value || null }) }) }), _jsxs(Field, { label: "Budgetmandaat (\u20AC)", children: [_jsx(ParsedInput, { inputMode: "decimal", placeholder: "0", display: value.budget_mandate_cents == null
|
|
452
|
+
? ""
|
|
453
|
+
: (value.budget_mandate_cents / 100).toLocaleString("nl-NL", { minimumFractionDigits: 2, maximumFractionDigits: 2 }), parse: (t) => (t.trim() === "" ? null : parseBedragNaarCenten(t) ?? Number.NaN), invalidText: "Ongeldig bedrag, bijvoorbeeld 1.250,00", onInvalid: (bad) => markInvalid("mandaat", bad), onValue: (c) => onChange({ budget_mandate_cents: c }) }), mandateCents > 0 && (_jsx(MandaatBalk, { totalCents: totalCents ?? 0, mandateCents: mandateCents }))] })] }), _jsxs(Section, { title: "Opdracht", children: [_jsx(Field, { label: "Klacht / melding", children: _jsx(Textarea, { rows: 4, value: value.complaint_description ?? "", placeholder: "Wat is er aan de hand?", onChange: (e) => onChange({ complaint_description: e.target.value || null }) }) }), _jsx(Field, { label: "Omschrijving voor de monteur", children: _jsx(Textarea, { rows: 4, value: value.technician_task_description ?? "", placeholder: "Wat moet er gebeuren?", onChange: (e) => onChange({ technician_task_description: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Pakketten toevoegen", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Werkzaamheden" }), packageLines.length === 0 && (_jsx("p", { className: "text-xs text-muted-foreground", children: "Nog geen werkzaamheden." })), !readOnly && travel && (_jsx("p", { className: travel.error ? "text-xs text-destructive" : "text-xs text-muted-foreground", children: travel.error
|
|
441
454
|
? travel.error
|
|
442
|
-
: `Reistijd: ${fmtMin(travel.one_way_minutes ?? 0)} enkele reis (${fmtMin(travel.round_trip_minutes ?? 0)} heen en terug) vanaf ${travel.origin_label ?? "de zaak"}` })), packageLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_5rem_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(OptionPicker, { value: l.package_id, items: options.packages, placeholder: "Kies een werkzaamheid\u2026", noun: "werkzaamheden", onSelect: (id) => updateLine(i, { package_id: id, quantity: l.quantity ?? 1 }), onClear: () => updateLine(i, { package_id: null }) }), l.description && !l.package_id && (_jsxs("p", { className: "truncate text-xs text-muted-foreground", children: ["Uit de mail: ", l.description] })), _jsx(PackageLineInfo, { line: l, pkg: pkgList.find((x) => x.id === l.package_id) ?? null, readOnly: !!readOnly, onQuarters: (q) => updateLine(i, { extra_quarters: q }) })] }), _jsx(
|
|
443
|
-
const n = Number(e.target.value);
|
|
444
|
-
updateLine(i, {
|
|
445
|
-
quantity: e.target.value === "" || Number.isNaN(n) ? null : n,
|
|
446
|
-
});
|
|
447
|
-
} }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `pkg-${i}`))), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => addLine("package"), children: [_jsx(Plus, { className: "mr-2 h-4 w-4" }), "Werkzaamheid toevoegen"] })] }), _jsxs("div", { className: "space-y-2 pt-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Materialen" }), materialLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(ArtikelPicker, { value: l.description, disabled: readOnly, suggestQuery: l.description ||
|
|
455
|
+
: `Reistijd: ${fmtMin(travel.one_way_minutes ?? 0)} enkele reis (${fmtMin(travel.round_trip_minutes ?? 0)} heen en terug) vanaf ${travel.origin_label ?? "de zaak"}` })), packageLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_5rem_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(OptionPicker, { value: l.package_id, items: options.packages, placeholder: "Kies een werkzaamheid\u2026", noun: "werkzaamheden", onSelect: (id) => updateLine(i, { package_id: id, quantity: l.quantity ?? 1 }), onClear: () => updateLine(i, { package_id: null }) }), l.description && !l.package_id && (_jsxs("p", { className: "truncate text-xs text-muted-foreground", children: ["Uit de mail: ", l.description] })), _jsx(PackageLineInfo, { line: l, pkg: pkgList.find((x) => x.id === l.package_id) ?? null, readOnly: !!readOnly, onQuarters: (q) => updateLine(i, { extra_quarters: q }) })] }), _jsx(ParsedInput, { inputMode: "decimal", placeholder: "Aantal", display: l.quantity == null ? "" : String(l.quantity).replace(".", ","), parse: parseAantal, invalidText: "Ongeldig aantal", onInvalid: (bad) => markInvalid(`pkg-${i}`, bad), onValue: (n) => updateLine(i, { quantity: n }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `pkg-${i}`))), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => addLine("package"), children: [_jsx(Plus, { className: "mr-2 h-4 w-4" }), "Werkzaamheid toevoegen"] })] }), _jsxs("div", { className: "space-y-2 pt-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Materialen" }), materialLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(ArtikelPicker, { value: l.description, disabled: readOnly, suggestQuery: l.description ||
|
|
448
456
|
value.technician_task_description ||
|
|
449
457
|
value.complaint_description ||
|
|
450
458
|
"", onPick: (a) => {
|
|
@@ -466,12 +474,7 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
466
474
|
return l.article_number in prijzen ? "geen prijs" : "";
|
|
467
475
|
const q = l.quantity == null ? 1 : Number(l.quantity) || 0;
|
|
468
476
|
return `${euro(pc)} × ${q} = ${euro(pc * q)}`;
|
|
469
|
-
})()] }), _jsx(ArtikelFoto, { url: fotos[l.article_number] ?? null, className: "h-8 w-8 shrink-0" })] })) : null] }), _jsx(
|
|
470
|
-
const n = Number(e.target.value);
|
|
471
|
-
updateLine(i, {
|
|
472
|
-
quantity: e.target.value === "" || Number.isNaN(n) ? null : n,
|
|
473
|
-
});
|
|
474
|
-
} }), _jsx(Input, { placeholder: "Eenheid", value: l.unit, onChange: (e) => updateLine(i, { unit: e.target.value }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `mat-${i}`))), !readOnly && (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsx("div", { className: "min-w-0", children: _jsx(ArtikelPicker, { value: "", suggestQuery: value.technician_task_description || value.complaint_description || "", onPick: (artikel) => {
|
|
477
|
+
})()] }), _jsx(ArtikelFoto, { url: fotos[l.article_number] ?? null, className: "h-8 w-8 shrink-0" })] })) : null] }), _jsx(ParsedInput, { inputMode: "decimal", placeholder: "Aantal", display: l.quantity == null ? "" : String(l.quantity).replace(".", ","), parse: parseAantal, invalidText: "Ongeldig aantal", onInvalid: (bad) => markInvalid(`mat-${i}`, bad), onValue: (n) => updateLine(i, { quantity: n }) }), _jsx(Input, { placeholder: "Eenheid", value: l.unit, onChange: (e) => updateLine(i, { unit: e.target.value }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `mat-${i}`))), !readOnly && (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsx("div", { className: "min-w-0", children: _jsx(ArtikelPicker, { value: "", suggestQuery: value.technician_task_description || value.complaint_description || "", onPick: (artikel) => {
|
|
475
478
|
const photoUrl = artikel.photo_url;
|
|
476
479
|
if (photoUrl && artikel.artikelcode) {
|
|
477
480
|
setFotos((current) => ({
|
|
@@ -484,10 +487,11 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
484
487
|
estimated_duration_minutes: combineDuration(e.target.value, durationMinutes(value.estimated_duration_minutes)),
|
|
485
488
|
}) }), _jsx("span", { className: "text-xs text-muted-foreground", children: "uur" })] }), _jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Input, { inputMode: "numeric", placeholder: "0", "aria-label": "Minuten", value: durationMinutes(value.estimated_duration_minutes), onChange: (e) => onChange({
|
|
486
489
|
estimated_duration_minutes: combineDuration(durationHours(value.estimated_duration_minutes), e.target.value),
|
|
487
|
-
}) }), _jsx("span", { className: "text-xs text-muted-foreground", children: "min" })] })] }) })] }), _jsx(Field, { label: "Monteur", children: _jsx(OptionPicker, { value: value.technician_id, items: options.technicians, placeholder: "Kies een monteur\u2026", noun: "monteurs", onSelect: (id) => onChange({ technician_id: id }), onClear: () => onChange({ technician_id: null }) }) })] }), _jsx(Section, { title: "Interne notities", children: _jsx(Textarea, { rows: 3, value: value.internal_notes ?? "", placeholder: "Alleen zichtbaar voor collega's", onChange: (e) => onChange({ internal_notes: e.target.value || null }) }) })] }), !readOnly && mandateCents > 0 && (_jsx("div", { className: "shrink-0 border-t border-border px-4 py-2", children: _jsx(MandaatBalk, { totalCents: totalCents ?? 0, mandateCents: mandateCents }) })), !readOnly && klantBlocked && (_jsxs("div", { className: "shrink-0 border-t border-destructive/40 bg-destructive/10 px-4 py-2 text-sm text-destructive", children: [_jsx("p", { className: "font-semibold", children: "Hier kan je geen werkbon van aanmaken" }), klantNotes[0] && _jsxs("p", { children: ["Reden: ", klantNotes[0]] })] })), !readOnly && (_jsxs("div", { className: "grid shrink-0 grid-cols-[minmax(0,1fr)_auto] gap-2 border-t border-border p-4", children: [_jsx(Button, { className: "w-full", onClick: onConfirm, disabled: saving ||
|
|
490
|
+
}) }), _jsx("span", { className: "text-xs text-muted-foreground", children: "min" })] })] }) })] }), _jsx(Field, { label: "Monteur", children: _jsx(OptionPicker, { value: value.technician_id, items: options.technicians, placeholder: "Kies een monteur\u2026", noun: "monteurs", onSelect: (id) => onChange({ technician_id: id }), onClear: () => onChange({ technician_id: null }) }) })] }), _jsx(Section, { title: "Interne notities", children: _jsx(Textarea, { rows: 3, value: value.internal_notes ?? "", placeholder: "Alleen zichtbaar voor collega's", onChange: (e) => onChange({ internal_notes: e.target.value || null }) }) }), showCompetenties && (_jsx(Section, { title: "Vereiste competenties", children: _jsx(CompetentiePicker, { value: value.vereiste_competentie_ids ?? [], disabled: readOnly || saving, onChange: (ids) => onChange({ vereiste_competentie_ids: ids }) }) }))] }), !readOnly && mandateCents > 0 && (_jsx("div", { className: "shrink-0 border-t border-border px-4 py-2", children: _jsx(MandaatBalk, { totalCents: totalCents ?? 0, mandateCents: mandateCents }) })), !readOnly && klantBlocked && (_jsxs("div", { className: "shrink-0 border-t border-destructive/40 bg-destructive/10 px-4 py-2 text-sm text-destructive", children: [_jsx("p", { className: "font-semibold", children: "Hier kan je geen werkbon van aanmaken" }), klantNotes[0] && _jsxs("p", { children: ["Reden: ", klantNotes[0]] })] })), !readOnly && (_jsxs("div", { className: "grid shrink-0 grid-cols-[minmax(0,1fr)_auto] gap-2 border-t border-border p-4", children: [_jsx(Button, { className: "w-full", onClick: onConfirm, disabled: saving ||
|
|
488
491
|
analysing ||
|
|
489
492
|
overMandate > 0 ||
|
|
490
493
|
klantBlocked ||
|
|
494
|
+
invalidFields.size > 0 ||
|
|
491
495
|
!value.customer_id ||
|
|
492
496
|
value.estimated_duration_minutes == null ||
|
|
493
497
|
value.estimated_duration_minutes <= 0, children: "Werkbon aanmaken" }), _jsx(Button, { variant: "outline", onClick: onReject, disabled: saving, children: "Afwijzen" })] }))] }));
|
|
@@ -515,3 +519,25 @@ function MandaatBalk({ totalCents, mandateCents }) {
|
|
|
515
519
|
const txt = pct > 100 ? "text-destructive" : pct >= 75 ? "text-orange-700" : "text-muted-foreground";
|
|
516
520
|
return (_jsxs("div", { className: "space-y-1 pt-1", children: [_jsxs("p", { className: `text-xs ${txt}`, children: [formatEuroCents(totalCents), " van ", formatEuroCents(mandateCents), " (", Math.round(pct), "%)", over > 0 && _jsxs("span", { className: "font-semibold", children: [" \u2014 ", formatEuroCents(over), " boven het mandaat"] })] }), _jsx("div", { className: "h-2 w-full overflow-hidden rounded-full bg-muted", children: _jsx("div", { className: `h-full ${bar} transition-all`, style: { width: `${Math.min(100, pct)}%` } }) })] }));
|
|
517
521
|
}
|
|
522
|
+
// Invoerveld dat de getypte tekst vasthoudt en pas een geldige waarde
|
|
523
|
+
// doorgeeft; ongeldige invoer geeft een melding en blokkeert aanmaken.
|
|
524
|
+
function ParsedInput({ display, parse, onValue, onInvalid, invalidText, placeholder, inputMode, }) {
|
|
525
|
+
const [text, setText] = useState(null);
|
|
526
|
+
const shown = text ?? display;
|
|
527
|
+
const parsed = text == null ? 0 : parse(text);
|
|
528
|
+
const bad = parsed != null && Number.isNaN(parsed);
|
|
529
|
+
useEffect(() => {
|
|
530
|
+
onInvalid(bad);
|
|
531
|
+
}, [bad, onInvalid]);
|
|
532
|
+
useEffect(() => () => onInvalid(false), [onInvalid]);
|
|
533
|
+
return (_jsxs("div", { className: "min-w-0", children: [_jsx(Input, { inputMode: inputMode, placeholder: placeholder, value: shown, "aria-invalid": bad || undefined, className: bad ? "border-destructive" : undefined, onChange: (e) => {
|
|
534
|
+
const t = e.target.value;
|
|
535
|
+
setText(t);
|
|
536
|
+
const n = parse(t);
|
|
537
|
+
if (n == null || !Number.isNaN(n))
|
|
538
|
+
onValue(n);
|
|
539
|
+
}, onBlur: () => {
|
|
540
|
+
if (!bad)
|
|
541
|
+
setText(null);
|
|
542
|
+
} }), bad && _jsx("p", { className: "mt-1 text-xs text-destructive", children: invalidText })] }));
|
|
543
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoAnalyse.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoAnalyse.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"useAutoAnalyse.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoAnalyse.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAU5C,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EAAE,EACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EACzC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,IAAI,GACjB,MAAM,EAAE,CAsGV"}
|