@rivil-solutions/site-kit 0.0.0-stage → 0.1.0
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 +97 -2
- package/bin/rivil.mjs +118 -0
- package/blocks/booking/block.json +7 -0
- package/blocks/booking/files/src/components/rivil/BookingForm.tsx +187 -0
- package/blocks/booking/files/src/pages/programare.astro +18 -0
- package/blocks/careers/block.json +7 -0
- package/blocks/careers/files/src/components/rivil/ApplyForm.tsx +62 -0
- package/blocks/careers/files/src/pages/cariere/[job].astro +49 -0
- package/blocks/careers/files/src/pages/cariere/index.astro +32 -0
- package/blocks/events/block.json +7 -0
- package/blocks/events/files/src/components/rivil/EventCheckout.tsx +93 -0
- package/blocks/events/files/src/pages/evenimente/[code].astro +35 -0
- package/blocks/events/files/src/pages/evenimente/comanda.astro +36 -0
- package/blocks/events/files/src/pages/evenimente/index.astro +30 -0
- package/blocks/newsletter/block.json +4 -0
- package/blocks/newsletter/files/src/components/rivil/Newsletter.astro +35 -0
- package/blocks/reviews/block.json +7 -0
- package/blocks/reviews/files/src/components/rivil/ReviewForm.tsx +73 -0
- package/blocks/reviews/files/src/pages/recenzii.astro +39 -0
- package/blocks/stay/block.json +7 -0
- package/blocks/stay/files/src/components/rivil/StayBooking.tsx +121 -0
- package/blocks/stay/files/src/pages/rezervare.astro +11 -0
- package/blocks/ui/block.json +1 -0
- package/blocks/ui/files/src/components/rivil/ui.tsx +99 -0
- package/blocks/ui/files/src/styles/rivil-blocks.css +47 -0
- package/dist/account.d.ts +84 -0
- package/dist/account.js +104 -0
- package/dist/astro-image.d.ts +29 -0
- package/dist/astro-image.js +12 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.js +153 -0
- package/dist/consent.d.ts +6 -0
- package/dist/consent.js +10 -0
- package/dist/content.d.ts +93 -0
- package/dist/content.js +85 -0
- package/dist/i18n.d.ts +30 -0
- package/dist/i18n.js +69 -0
- package/dist/images.d.ts +13 -0
- package/dist/images.js +26 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/modules.d.ts +288 -0
- package/dist/modules.js +49 -0
- package/dist/proxy.d.ts +47 -0
- package/dist/proxy.js +82 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +6 -0
- package/dist/react/texts.d.ts +17 -0
- package/dist/react/texts.js +28 -0
- package/dist/react/useApplication.d.ts +67 -0
- package/dist/react/useApplication.js +94 -0
- package/dist/react/useBooking.d.ts +81 -0
- package/dist/react/useBooking.js +151 -0
- package/dist/react/useEventCheckout.d.ts +48 -0
- package/dist/react/useEventCheckout.js +104 -0
- package/dist/react/useReview.d.ts +58 -0
- package/dist/react/useReview.js +69 -0
- package/dist/react/useStay.d.ts +82 -0
- package/dist/react/useStay.js +105 -0
- package/dist/seo.d.ts +27 -0
- package/dist/seo.js +36 -0
- package/dist/shop.d.ts +111 -0
- package/dist/shop.js +167 -0
- package/dist/visitor.d.ts +7 -0
- package/dist/visitor.js +17 -0
- package/dist/web.d.ts +83 -0
- package/dist/web.js +131 -0
- package/dist/webhook.d.ts +20 -0
- package/dist/webhook.js +39 -0
- package/package.json +62 -4
- package/themes/aer.css +12 -0
- package/themes/cabana.css +12 -0
- package/themes/curte.css +12 -0
- package/themes/lumen.css +12 -0
- package/themes/miez.css +12 -0
- package/themes/solvar.css +12 -0
package/dist/proxy.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { visitorIp } from './visitor.js';
|
|
2
|
+
const R = (method, path, extra = {}) => ({ method, path, ...extra });
|
|
3
|
+
const CODE = '[A-Za-z0-9_-]{1,64}';
|
|
4
|
+
/**
|
|
5
|
+
* Ce poate cere browserul prin site, pe module. Doar citiri publice și acțiunile unui vizitator (rezervă, aplică, comandă);
|
|
6
|
+
* nimic din administrare. Lista se poate restrânge la modulele site-ului: `routes: [...MODULE_ROUTES.booking, ...MODULE_ROUTES.forms]`.
|
|
7
|
+
*/
|
|
8
|
+
export const MODULE_ROUTES = {
|
|
9
|
+
forms: [R('POST', new RegExp(`^forms/${CODE}$`))],
|
|
10
|
+
newsletter: [R('POST', /^newsletter$/)],
|
|
11
|
+
addresses: [R('GET', /^addresses\/(places|streets|validate)$/)],
|
|
12
|
+
booking: [R('GET', /^booking$/), R('POST', /^booking$/), R('POST', /^booking\/hold$/), R('DELETE', /^booking\/hold$/), R('POST', /^booking\/(lead|waitlist)$/)],
|
|
13
|
+
stay: [R('GET', /^stay\/search$/), R('POST', /^stay\/reserve$/), R('GET', /^stay\/manage$/), R('POST', /^stay\/manage$/)],
|
|
14
|
+
careers: [R('GET', /^careers$/), R('PUT', /^careers$/), R('POST', /^careers$/, { body: 'multipart' })],
|
|
15
|
+
reviews: [R('GET', /^reviews$/), R('POST', /^reviews$/), R('GET', /^reviews\/wall$/)],
|
|
16
|
+
events: [
|
|
17
|
+
R('GET', /^events$/),
|
|
18
|
+
R('GET', new RegExp(`^events/${CODE}$`)),
|
|
19
|
+
R('POST', new RegExp(`^events/${CODE}/(quote|orders|waitlist)$`)),
|
|
20
|
+
R('GET', new RegExp(`^events/orders/${CODE}$`)),
|
|
21
|
+
R('GET', new RegExp(`^events/orders/${CODE}/pdf$`), { file: true }),
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
export const ALL_MODULE_ROUTES = Object.values(MODULE_ROUTES).flat();
|
|
25
|
+
const json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json', 'cache-control': 'no-store' } });
|
|
26
|
+
const fail = (status, code, message) => json({ error: { code, message } }, status);
|
|
27
|
+
/**
|
|
28
|
+
* Proxy-ul modulelor: browserul vorbește doar cu site-ul (fără CORS, fără cheie în pagină), site-ul cheamă `/api/site/v1` cu cheia de site.
|
|
29
|
+
* Trec doar rutele din listă, cu adresa vizitatorului. Răspunsul nu se ține în memorie: locurile și orele libere trebuie să fie cele de acum.
|
|
30
|
+
* În Astro (`src/pages/api/rivil/[...path].ts`): `const proxy = siteProxy({ client }); export const ALL = (c) => proxy({ request: c.request, path: c.params.path, clientAddress: c.clientAddress })`.
|
|
31
|
+
*/
|
|
32
|
+
export function siteProxy(o) {
|
|
33
|
+
const routes = o.routes ?? ALL_MODULE_ROUTES;
|
|
34
|
+
const maxUpload = o.maxUploadBytes ?? 25 * 1024 * 1024;
|
|
35
|
+
return async (c) => {
|
|
36
|
+
const { request } = c;
|
|
37
|
+
const url = new URL(request.url);
|
|
38
|
+
const path = String(c.path ?? '').replace(/^\/+|\/+$/g, '');
|
|
39
|
+
const route = routes.find((r) => r.method === request.method && r.path.test(path));
|
|
40
|
+
if (!route)
|
|
41
|
+
return fail(404, 'not_found', 'Not found');
|
|
42
|
+
const origin = request.headers.get('origin');
|
|
43
|
+
const allowed = new Set([url.origin, ...(o.origins ?? []).map((x) => new URL(x).origin)]);
|
|
44
|
+
if (origin && !allowed.has(origin))
|
|
45
|
+
return fail(403, 'forbidden', 'Forbidden');
|
|
46
|
+
const kind = route.body ?? (['POST', 'PUT', 'PATCH', 'DELETE'].includes(route.method) ? 'json' : 'none');
|
|
47
|
+
const type = request.headers.get('content-type') ?? '';
|
|
48
|
+
let jsonBody;
|
|
49
|
+
let body;
|
|
50
|
+
if (kind === 'multipart') {
|
|
51
|
+
// un formular străin poate trimite multipart fără CORS: aici originea e obligatorie
|
|
52
|
+
if (!origin || !type.startsWith('multipart/form-data'))
|
|
53
|
+
return fail(415, 'invalid_body', 'multipart/form-data');
|
|
54
|
+
if (!(Number(request.headers.get('content-length')) <= maxUpload))
|
|
55
|
+
return fail(413, 'too_large', 'Too large');
|
|
56
|
+
body = await request.arrayBuffer();
|
|
57
|
+
}
|
|
58
|
+
else if (kind === 'json') {
|
|
59
|
+
if (!type.includes('application/json'))
|
|
60
|
+
return fail(415, 'invalid_json', 'JSON');
|
|
61
|
+
jsonBody = await request.json().catch(() => undefined);
|
|
62
|
+
if (jsonBody === undefined)
|
|
63
|
+
return fail(400, 'invalid_json', 'JSON');
|
|
64
|
+
}
|
|
65
|
+
const res = await o.client
|
|
66
|
+
.request(`/${path}${url.search}`, {
|
|
67
|
+
method: route.method,
|
|
68
|
+
json: jsonBody,
|
|
69
|
+
body,
|
|
70
|
+
headers: kind === 'multipart' ? { 'content-type': type } : undefined,
|
|
71
|
+
visitorIp: visitorIp(request, () => c.clientAddress ?? ''),
|
|
72
|
+
timeoutMs: kind === 'multipart' ? 60_000 : 20_000,
|
|
73
|
+
})
|
|
74
|
+
.catch(() => null);
|
|
75
|
+
if (!res)
|
|
76
|
+
return fail(502, 'unavailable', 'Serviciul nu răspunde.');
|
|
77
|
+
if (route.file && res.ok) {
|
|
78
|
+
return new Response(res.body, { headers: { 'content-type': res.headers.get('content-type') ?? 'application/octet-stream', 'content-disposition': res.headers.get('content-disposition') ?? 'attachment', 'cache-control': 'private, no-store' } });
|
|
79
|
+
}
|
|
80
|
+
return new Response(res.status === 204 ? null : res.body, { status: res.status, headers: { 'content-type': res.headers.get('content-type') ?? 'application/json', 'cache-control': 'no-store' } });
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useBooking, type BookingState, type UseBookingOptions } from './useBooking.js';
|
|
2
|
+
export { useStay, type StayBooked, type StayRoom, type StayState } from './useStay.js';
|
|
3
|
+
export { useApplication, APPLY_LONG_FIELDS, APPLY_TEXT_FIELDS, CV_ACCEPT, type ApplicationState } from './useApplication.js';
|
|
4
|
+
export { useReview, pickSurvey, type ReviewQuestion, type ReviewState } from './useReview.js';
|
|
5
|
+
export { useEventCheckout, ticketOnSale, ticketState, type EventCheckoutState } from './useEventCheckout.js';
|
|
6
|
+
export { formText, type FormText } from './texts.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useBooking } from './useBooking.js';
|
|
2
|
+
export { useStay } from './useStay.js';
|
|
3
|
+
export { useApplication, APPLY_LONG_FIELDS, APPLY_TEXT_FIELDS, CV_ACCEPT } from './useApplication.js';
|
|
4
|
+
export { useReview, pickSurvey } from './useReview.js';
|
|
5
|
+
export { useEventCheckout, ticketOnSale, ticketState } from './useEventCheckout.js';
|
|
6
|
+
export { formText } from './texts.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Mesajele de validare ale formularelor, în limba paginii. Alte limbi decât română primesc engleza. */
|
|
2
|
+
declare const RO: {
|
|
3
|
+
required: string;
|
|
4
|
+
answers: string;
|
|
5
|
+
consents: string;
|
|
6
|
+
nameEmail: string;
|
|
7
|
+
email: string;
|
|
8
|
+
phone: string;
|
|
9
|
+
pickTime: string;
|
|
10
|
+
dates: string;
|
|
11
|
+
cv: string;
|
|
12
|
+
cvSize: string;
|
|
13
|
+
tickets: string;
|
|
14
|
+
};
|
|
15
|
+
export type FormText = keyof typeof RO;
|
|
16
|
+
export declare const formText: (lang: string, key: FormText) => string;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Mesajele de validare ale formularelor, în limba paginii. Alte limbi decât română primesc engleza. */
|
|
2
|
+
const RO = {
|
|
3
|
+
required: 'Completează câmpurile obligatorii.',
|
|
4
|
+
answers: 'Răspunde la întrebările obligatorii.',
|
|
5
|
+
consents: 'Acceptă consimțămintele obligatorii.',
|
|
6
|
+
nameEmail: 'Completează numele și un email valid.',
|
|
7
|
+
email: 'Completează un email valid.',
|
|
8
|
+
phone: 'Completează un telefon valid.',
|
|
9
|
+
pickTime: 'Alege mai întâi ora.',
|
|
10
|
+
dates: 'Alege data de sosire și cea de plecare.',
|
|
11
|
+
cv: 'Atașează CV-ul.',
|
|
12
|
+
cvSize: 'CV-ul e prea mare.',
|
|
13
|
+
tickets: 'Alege cel puțin un bilet.',
|
|
14
|
+
};
|
|
15
|
+
const EN = {
|
|
16
|
+
required: 'Fill in the required fields.',
|
|
17
|
+
answers: 'Please answer the required questions.',
|
|
18
|
+
consents: 'Please accept the required consents.',
|
|
19
|
+
nameEmail: 'Enter your name and a valid email.',
|
|
20
|
+
email: 'Enter a valid email.',
|
|
21
|
+
phone: 'Enter a valid phone number.',
|
|
22
|
+
pickTime: 'Pick a time first.',
|
|
23
|
+
dates: 'Pick your check-in and check-out dates.',
|
|
24
|
+
cv: 'Attach your CV.',
|
|
25
|
+
cvSize: 'The CV is too large.',
|
|
26
|
+
tickets: 'Pick at least one ticket.',
|
|
27
|
+
};
|
|
28
|
+
export const formText = (lang, key) => (lang === 'ro' ? RO : EN)[key];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ApplyInfo } from '../modules.js';
|
|
2
|
+
import { type RivilFetch } from '../web.js';
|
|
3
|
+
/** Câmpurile scurte pe care firma le poate cere la aplicare, în ordinea din formular. */
|
|
4
|
+
export declare const APPLY_TEXT_FIELDS: readonly ["phone", "city", "linkedin", "salary", "start"];
|
|
5
|
+
export declare const APPLY_LONG_FIELDS: readonly ["message", "cover"];
|
|
6
|
+
/** Tipurile de fișier pentru CV, după numele din ERP. */
|
|
7
|
+
export declare const CV_ACCEPT: Record<string, string>;
|
|
8
|
+
/** Aplicarea la un job (sau spontană, cu `job` gol): câmpurile, întrebările, CV-ul și consimțămintele vin din ERP; trimiterea e multipart. */
|
|
9
|
+
export declare function useApplication(o: {
|
|
10
|
+
info: ApplyInfo;
|
|
11
|
+
job?: string;
|
|
12
|
+
lang: string;
|
|
13
|
+
fetcher?: RivilFetch;
|
|
14
|
+
}): {
|
|
15
|
+
textFields: {
|
|
16
|
+
on: boolean;
|
|
17
|
+
required: boolean;
|
|
18
|
+
label: string;
|
|
19
|
+
key: "city" | "salary" | "phone" | "start" | "linkedin";
|
|
20
|
+
}[];
|
|
21
|
+
longFields: {
|
|
22
|
+
on: boolean;
|
|
23
|
+
required: boolean;
|
|
24
|
+
label: string;
|
|
25
|
+
key: "message" | "cover";
|
|
26
|
+
}[];
|
|
27
|
+
cv: {
|
|
28
|
+
on: boolean;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
maxMb?: number;
|
|
31
|
+
types?: string[];
|
|
32
|
+
};
|
|
33
|
+
cvAccept: string;
|
|
34
|
+
questions: {
|
|
35
|
+
id: string;
|
|
36
|
+
type: string;
|
|
37
|
+
label: string;
|
|
38
|
+
help?: string;
|
|
39
|
+
required?: boolean;
|
|
40
|
+
options?: string[];
|
|
41
|
+
min?: number;
|
|
42
|
+
max?: number;
|
|
43
|
+
showIf?: unknown;
|
|
44
|
+
}[];
|
|
45
|
+
consents: import("../modules.js").Consent[];
|
|
46
|
+
texts: Record<string, string>;
|
|
47
|
+
name: string;
|
|
48
|
+
setName: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
49
|
+
email: string;
|
|
50
|
+
setEmail: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
51
|
+
extra: Record<string, string>;
|
|
52
|
+
setExtra: (k: string, v: string) => void;
|
|
53
|
+
answers: Record<string, unknown>;
|
|
54
|
+
setAnswer: (id: string, v: unknown) => void;
|
|
55
|
+
files: Record<string, File | undefined>;
|
|
56
|
+
setFile: (id: string, file: File | undefined) => void;
|
|
57
|
+
accepted: Record<string, boolean>;
|
|
58
|
+
setAccepted: (k: string, v: boolean) => void;
|
|
59
|
+
trap: string;
|
|
60
|
+
setTrap: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
61
|
+
busy: boolean;
|
|
62
|
+
error: string;
|
|
63
|
+
/** Mesajul de mulțumire din ERP, după trimitere. */
|
|
64
|
+
done: string | null;
|
|
65
|
+
submit(): Promise<void>;
|
|
66
|
+
};
|
|
67
|
+
export type ApplicationState = ReturnType<typeof useApplication>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { errorMessage, isEmail, isEmpty, rivilFetch } from '../web.js';
|
|
3
|
+
import { formText } from './texts.js';
|
|
4
|
+
/** Câmpurile scurte pe care firma le poate cere la aplicare, în ordinea din formular. */
|
|
5
|
+
export const APPLY_TEXT_FIELDS = ['phone', 'city', 'linkedin', 'salary', 'start'];
|
|
6
|
+
export const APPLY_LONG_FIELDS = ['message', 'cover'];
|
|
7
|
+
/** Tipurile de fișier pentru CV, după numele din ERP. */
|
|
8
|
+
export const CV_ACCEPT = { pdf: '.pdf', word: '.doc,.docx', image: '.jpg,.jpeg,.png' };
|
|
9
|
+
/** Aplicarea la un job (sau spontană, cu `job` gol): câmpurile, întrebările, CV-ul și consimțămintele vin din ERP; trimiterea e multipart. */
|
|
10
|
+
export function useApplication(o) {
|
|
11
|
+
const f = o.fetcher ?? rivilFetch;
|
|
12
|
+
const fieldsCfg = o.info.fields ?? {};
|
|
13
|
+
const cv = o.info.cv ?? { on: false };
|
|
14
|
+
const questions = (o.info.questions ?? []).filter((q) => !q.showIf);
|
|
15
|
+
const consents = (o.info.consents ?? []).filter((c) => c.enabled !== false);
|
|
16
|
+
const [name, setName] = useState('');
|
|
17
|
+
const [email, setEmail] = useState('');
|
|
18
|
+
const [extra, setExtra] = useState({});
|
|
19
|
+
const [answers, setAnswers] = useState({});
|
|
20
|
+
const [files, setFiles] = useState({});
|
|
21
|
+
const [accepted, setAcceptedState] = useState({});
|
|
22
|
+
const [trap, setTrap] = useState('');
|
|
23
|
+
const [busy, setBusy] = useState(false);
|
|
24
|
+
const [error, setError] = useState('');
|
|
25
|
+
const [done, setDone] = useState(null);
|
|
26
|
+
return {
|
|
27
|
+
textFields: APPLY_TEXT_FIELDS.filter((k) => fieldsCfg[k]?.on).map((k) => ({ key: k, ...fieldsCfg[k] })),
|
|
28
|
+
longFields: APPLY_LONG_FIELDS.filter((k) => fieldsCfg[k]?.on).map((k) => ({ key: k, ...fieldsCfg[k] })),
|
|
29
|
+
cv,
|
|
30
|
+
cvAccept: (cv.types ?? ['pdf', 'word']).map((x) => CV_ACCEPT[x] ?? '').filter(Boolean).join(','),
|
|
31
|
+
questions,
|
|
32
|
+
consents,
|
|
33
|
+
texts: o.info.texts ?? {},
|
|
34
|
+
name,
|
|
35
|
+
setName,
|
|
36
|
+
email,
|
|
37
|
+
setEmail,
|
|
38
|
+
extra,
|
|
39
|
+
setExtra: (k, v) => setExtra((s) => ({ ...s, [k]: v })),
|
|
40
|
+
answers,
|
|
41
|
+
setAnswer: (id, v) => setAnswers((a) => ({ ...a, [id]: v })),
|
|
42
|
+
files,
|
|
43
|
+
setFile: (id, file) => setFiles((s) => ({ ...s, [id]: file })),
|
|
44
|
+
accepted,
|
|
45
|
+
setAccepted: (k, v) => setAcceptedState((s) => ({ ...s, [k]: v })),
|
|
46
|
+
trap,
|
|
47
|
+
setTrap,
|
|
48
|
+
busy,
|
|
49
|
+
error,
|
|
50
|
+
/** Mesajul de mulțumire din ERP, după trimitere. */
|
|
51
|
+
done,
|
|
52
|
+
async submit() {
|
|
53
|
+
setError('');
|
|
54
|
+
if (!name.trim() || !isEmail(email))
|
|
55
|
+
return setError(formText(o.lang, 'nameEmail'));
|
|
56
|
+
for (const k of [...APPLY_TEXT_FIELDS, ...APPLY_LONG_FIELDS])
|
|
57
|
+
if (fieldsCfg[k]?.on && fieldsCfg[k].required && !extra[k]?.trim())
|
|
58
|
+
return setError(formText(o.lang, 'required'));
|
|
59
|
+
if (questions.some((q) => q.required && isEmpty(q.type === 'file' ? files[q.id] : answers[q.id])))
|
|
60
|
+
return setError(formText(o.lang, 'answers'));
|
|
61
|
+
if (consents.some((c) => c.required && !accepted[c.key]))
|
|
62
|
+
return setError(formText(o.lang, 'consents'));
|
|
63
|
+
if (cv.on && cv.required && !files.cv)
|
|
64
|
+
return setError(formText(o.lang, 'cv'));
|
|
65
|
+
if (files.cv && files.cv.size > (cv.maxMb ?? 10) * 1024 * 1024)
|
|
66
|
+
return setError(formText(o.lang, 'cvSize'));
|
|
67
|
+
const body = new FormData();
|
|
68
|
+
body.set('job', o.job ?? '');
|
|
69
|
+
body.set('lang', o.lang);
|
|
70
|
+
body.set('name', name.trim());
|
|
71
|
+
body.set('email', email.trim());
|
|
72
|
+
body.set('fields', JSON.stringify(Object.fromEntries(Object.entries(extra).filter(([, v]) => v.trim()))));
|
|
73
|
+
body.set('answers', JSON.stringify(Object.fromEntries(Object.entries(answers).filter(([, v]) => !isEmpty(v)))));
|
|
74
|
+
body.set('consents', JSON.stringify(accepted));
|
|
75
|
+
body.set('website', trap);
|
|
76
|
+
if (files.cv)
|
|
77
|
+
body.set('cv', files.cv);
|
|
78
|
+
for (const q of questions)
|
|
79
|
+
if (q.type === 'file' && files[q.id])
|
|
80
|
+
body.set(`file_${q.id}`, files[q.id]);
|
|
81
|
+
setBusy(true);
|
|
82
|
+
try {
|
|
83
|
+
const out = await f('careers', { body });
|
|
84
|
+
setDone(out?.thanks ?? '');
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
setError(errorMessage(e));
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
setBusy(false);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { BookingCatalog, BookingField, Consent, Slot } from '../modules.js';
|
|
2
|
+
import { type BookingStep, type RivilFetch } from '../web.js';
|
|
3
|
+
export type UseBookingOptions = {
|
|
4
|
+
/** Catalogul încărcat pe server (`modules.booking.catalog(lang)`). */
|
|
5
|
+
catalog: BookingCatalog;
|
|
6
|
+
lang: string;
|
|
7
|
+
/** Serviciul ales deja (de pe pagina lui). */
|
|
8
|
+
initialService?: string;
|
|
9
|
+
/** Răspunsuri completate dinainte (clientul intrat în cont), pe cheile câmpurilor. */
|
|
10
|
+
prefill?: Record<string, unknown>;
|
|
11
|
+
/** Câte zile înainte se caută ore libere (implicit 28, cel mult orizontul firmei). */
|
|
12
|
+
daysAhead?: number;
|
|
13
|
+
fetcher?: RivilFetch;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Programarea online fără aspect: servicii, locație, specialist, zi și oră (ținută în ERP cât se completează datele), datele omului.
|
|
17
|
+
* Componenta desenează pașii; aici sunt starea și cererile.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useBooking(o: UseBookingOptions): {
|
|
20
|
+
catalog: BookingCatalog;
|
|
21
|
+
step: BookingStep;
|
|
22
|
+
steps: BookingStep[];
|
|
23
|
+
stepIndex: number;
|
|
24
|
+
go: (s: BookingStep) => void;
|
|
25
|
+
next: () => void;
|
|
26
|
+
back: () => void;
|
|
27
|
+
services: import("../modules.js").BookingService[];
|
|
28
|
+
chosen: import("../modules.js").BookingService[];
|
|
29
|
+
picked: string[];
|
|
30
|
+
toggle: (id: string) => void;
|
|
31
|
+
locations: {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
address?: string;
|
|
35
|
+
}[];
|
|
36
|
+
locationId: string;
|
|
37
|
+
chooseLocation: (id: string) => void;
|
|
38
|
+
employees: {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
locationIds?: string[];
|
|
42
|
+
}[];
|
|
43
|
+
/** `''` = oricare specialist. */
|
|
44
|
+
employeeId: string;
|
|
45
|
+
chooseEmployee: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
46
|
+
slots: Slot[] | null;
|
|
47
|
+
loadingSlots: boolean;
|
|
48
|
+
byDay: Map<string, Slot[]>;
|
|
49
|
+
day: string | null;
|
|
50
|
+
chooseDay: (d: string | null) => void;
|
|
51
|
+
daySlots: Slot[];
|
|
52
|
+
slot: Slot | null;
|
|
53
|
+
hold: {
|
|
54
|
+
token: string;
|
|
55
|
+
expiresAt?: string;
|
|
56
|
+
} | null;
|
|
57
|
+
holdMinutes: number;
|
|
58
|
+
/** Ține ora în ERP și trece la date. */
|
|
59
|
+
pickSlot(s: Slot): Promise<void>;
|
|
60
|
+
fields: BookingField[];
|
|
61
|
+
consents: Consent[];
|
|
62
|
+
answers: Record<string, unknown>;
|
|
63
|
+
setAnswer: (key: string, v: unknown) => void;
|
|
64
|
+
accepted: Record<string, boolean>;
|
|
65
|
+
setAccepted: (key: string, v: boolean) => void;
|
|
66
|
+
/** Câmpul capcană: rămâne gol la oameni. */
|
|
67
|
+
trap: string;
|
|
68
|
+
setTrap: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
69
|
+
minutes: number;
|
|
70
|
+
total: number;
|
|
71
|
+
currency: string;
|
|
72
|
+
busy: boolean;
|
|
73
|
+
error: string;
|
|
74
|
+
done: {
|
|
75
|
+
start: string;
|
|
76
|
+
message?: string;
|
|
77
|
+
} | null;
|
|
78
|
+
submit(): Promise<void>;
|
|
79
|
+
reset(): void;
|
|
80
|
+
};
|
|
81
|
+
export type BookingState = ReturnType<typeof useBooking>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { addDays, bookingPlan, errorMessage, firstMissing, groupByDay, isoDay, rivilFetch } from '../web.js';
|
|
3
|
+
import { formText } from './texts.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programarea online fără aspect: servicii, locație, specialist, zi și oră (ținută în ERP cât se completează datele), datele omului.
|
|
6
|
+
* Componenta desenează pașii; aici sunt starea și cererile.
|
|
7
|
+
*/
|
|
8
|
+
export function useBooking(o) {
|
|
9
|
+
const f = o.fetcher ?? rivilFetch;
|
|
10
|
+
const c = o.catalog;
|
|
11
|
+
const [step, setStep] = useState('services');
|
|
12
|
+
const [picked, setPicked] = useState(o.initialService ? [o.initialService] : []);
|
|
13
|
+
const [locationId, setLocationId] = useState('');
|
|
14
|
+
const [employeeId, setEmployeeId] = useState('');
|
|
15
|
+
const [slots, setSlots] = useState(null);
|
|
16
|
+
const [loadingSlots, setLoadingSlots] = useState(false);
|
|
17
|
+
const [day, setDay] = useState(null);
|
|
18
|
+
const [slot, setSlot] = useState(null);
|
|
19
|
+
const [hold, setHold] = useState(null);
|
|
20
|
+
const [answers, setAnswers] = useState(() => ({ ...o.prefill }));
|
|
21
|
+
const [consents, setConsents] = useState({});
|
|
22
|
+
const [trap, setTrap] = useState('');
|
|
23
|
+
const [busy, setBusy] = useState(false);
|
|
24
|
+
const [error, setError] = useState('');
|
|
25
|
+
const [done, setDone] = useState(null);
|
|
26
|
+
const plan = useMemo(() => bookingPlan(c, picked, locationId), [c, picked, locationId]);
|
|
27
|
+
const fields = (c.form?.fields ?? []).filter((x) => x.enabled !== false);
|
|
28
|
+
const consentList = (c.form?.consents ?? []).filter((x) => x.enabled !== false);
|
|
29
|
+
const at = plan.steps.indexOf(step);
|
|
30
|
+
const horizon = Math.min(c.config?.horizonDays ?? 30, o.daysAhead ?? 28);
|
|
31
|
+
const pickedKey = picked.join(',');
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (step !== 'time' || !picked.length)
|
|
34
|
+
return;
|
|
35
|
+
let off = false;
|
|
36
|
+
const today = new Date();
|
|
37
|
+
setSlots(null);
|
|
38
|
+
setLoadingSlots(true);
|
|
39
|
+
f('booking', { query: { services: pickedKey, from: isoDay(today), to: isoDay(addDays(today, horizon)), location: locationId, employee: employeeId } })
|
|
40
|
+
.then((r) => !off && setSlots(r.slots ?? []))
|
|
41
|
+
.catch(() => !off && setSlots([]))
|
|
42
|
+
.finally(() => !off && setLoadingSlots(false));
|
|
43
|
+
return () => {
|
|
44
|
+
off = true;
|
|
45
|
+
};
|
|
46
|
+
}, [step, pickedKey, locationId, employeeId]);
|
|
47
|
+
const byDay = useMemo(() => groupByDay(slots ?? []), [slots]);
|
|
48
|
+
const go = (s) => {
|
|
49
|
+
setError('');
|
|
50
|
+
setStep(s);
|
|
51
|
+
};
|
|
52
|
+
const next = () => go(plan.steps[Math.min(at + 1, plan.steps.length - 1)]);
|
|
53
|
+
const back = () => go(plan.steps[Math.max(at - 1, 0)]);
|
|
54
|
+
return {
|
|
55
|
+
catalog: c,
|
|
56
|
+
step,
|
|
57
|
+
steps: plan.steps,
|
|
58
|
+
stepIndex: at,
|
|
59
|
+
go,
|
|
60
|
+
next,
|
|
61
|
+
back,
|
|
62
|
+
services: c.services,
|
|
63
|
+
chosen: plan.chosen,
|
|
64
|
+
picked,
|
|
65
|
+
toggle: (id) => setPicked((p) => (p.includes(id) ? p.filter((x) => x !== id) : [...p, id])),
|
|
66
|
+
locations: plan.locations,
|
|
67
|
+
locationId,
|
|
68
|
+
chooseLocation: (id) => {
|
|
69
|
+
setLocationId(id);
|
|
70
|
+
setEmployeeId('');
|
|
71
|
+
},
|
|
72
|
+
employees: plan.employees,
|
|
73
|
+
/** `''` = oricare specialist. */
|
|
74
|
+
employeeId,
|
|
75
|
+
chooseEmployee: setEmployeeId,
|
|
76
|
+
slots,
|
|
77
|
+
loadingSlots,
|
|
78
|
+
byDay,
|
|
79
|
+
day,
|
|
80
|
+
chooseDay: (d) => {
|
|
81
|
+
setDay(d);
|
|
82
|
+
setSlot(null);
|
|
83
|
+
},
|
|
84
|
+
daySlots: day ? (byDay.get(day) ?? []) : [],
|
|
85
|
+
slot,
|
|
86
|
+
hold,
|
|
87
|
+
holdMinutes: c.config?.holdMinutes ?? 10,
|
|
88
|
+
/** Ține ora în ERP și trece la date. */
|
|
89
|
+
async pickSlot(s) {
|
|
90
|
+
setError('');
|
|
91
|
+
setSlot(s);
|
|
92
|
+
try {
|
|
93
|
+
const out = await f('booking/hold', {
|
|
94
|
+
json: { services: picked, start: s.start, employeeId: employeeId || s.employees?.[0]?.id, locationId: locationId || undefined, token: hold?.token },
|
|
95
|
+
});
|
|
96
|
+
setHold({ token: out.token, expiresAt: out.expiresAt });
|
|
97
|
+
go('details');
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
setSlot(null);
|
|
101
|
+
setHold(null);
|
|
102
|
+
setError(errorMessage(e));
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
fields,
|
|
106
|
+
consents: consentList,
|
|
107
|
+
answers,
|
|
108
|
+
setAnswer: (key, v) => setAnswers((a) => ({ ...a, [key]: v })),
|
|
109
|
+
accepted: consents,
|
|
110
|
+
setAccepted: (key, v) => setConsents((s) => ({ ...s, [key]: v })),
|
|
111
|
+
/** Câmpul capcană: rămâne gol la oameni. */
|
|
112
|
+
trap,
|
|
113
|
+
setTrap,
|
|
114
|
+
minutes: plan.minutes,
|
|
115
|
+
total: plan.total,
|
|
116
|
+
currency: c.currency || 'RON',
|
|
117
|
+
busy,
|
|
118
|
+
error,
|
|
119
|
+
done,
|
|
120
|
+
async submit() {
|
|
121
|
+
setError('');
|
|
122
|
+
if (!hold)
|
|
123
|
+
return setError(formText(o.lang, 'pickTime'));
|
|
124
|
+
if (firstMissing(fields, (x) => answers[x.key]))
|
|
125
|
+
return setError(formText(o.lang, 'required'));
|
|
126
|
+
if (firstMissing(consentList, (x) => consents[x.key]))
|
|
127
|
+
return setError(formText(o.lang, 'consents'));
|
|
128
|
+
setBusy(true);
|
|
129
|
+
try {
|
|
130
|
+
const out = await f('booking', { json: { holdToken: hold.token, answers, consents, website: trap, lang: o.lang } });
|
|
131
|
+
setDone({ start: out.start, message: out.message });
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
setError(errorMessage(e));
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
setBusy(false);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
reset() {
|
|
141
|
+
setDone(null);
|
|
142
|
+
setPicked([]);
|
|
143
|
+
setSlot(null);
|
|
144
|
+
setHold(null);
|
|
145
|
+
setDay(null);
|
|
146
|
+
setAnswers({ ...o.prefill });
|
|
147
|
+
setConsents({});
|
|
148
|
+
go('services');
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { EventDetail, TicketType } from '../modules.js';
|
|
2
|
+
import { type RivilFetch } from '../web.js';
|
|
3
|
+
/** Starea de vânzare a unui tip de bilet, cu „epuizat” când nu mai sunt locuri. */
|
|
4
|
+
export declare const ticketState: (t: TicketType) => "open" | "soldout" | "soon" | "closed" | "paid";
|
|
5
|
+
export declare const ticketOnSale: (t: TicketType) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Înscrierea la un eveniment: bilete, cupon, cumpărător, întrebări. La biletele plătite, ERP-ul dă adresa de plată și omul pleacă acolo;
|
|
8
|
+
* la cele gratuite comanda e gata și se merge la `successPath` cu `order_token`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useEventCheckout(o: {
|
|
11
|
+
event: Pick<EventDetail, 'code' | 'currency' | 'types' | 'questions' | 'waitlistEnabled'>;
|
|
12
|
+
lang: string;
|
|
13
|
+
successPath: string;
|
|
14
|
+
access?: string;
|
|
15
|
+
invite?: string;
|
|
16
|
+
fetcher?: RivilFetch;
|
|
17
|
+
}): {
|
|
18
|
+
types: TicketType[];
|
|
19
|
+
questions: import("../modules.js").EventQuestion[];
|
|
20
|
+
qty: Record<string, number>;
|
|
21
|
+
change(t: TicketType, n: number): void;
|
|
22
|
+
subtotal: number;
|
|
23
|
+
total: number;
|
|
24
|
+
discount: number;
|
|
25
|
+
coupon: string;
|
|
26
|
+
setCoupon(v: string): void;
|
|
27
|
+
couponError: string;
|
|
28
|
+
applyCoupon(): Promise<void>;
|
|
29
|
+
buyer: {
|
|
30
|
+
name: string;
|
|
31
|
+
email: string;
|
|
32
|
+
phone: string;
|
|
33
|
+
};
|
|
34
|
+
setBuyer: (patch: Partial<{
|
|
35
|
+
name: string;
|
|
36
|
+
email: string;
|
|
37
|
+
phone: string;
|
|
38
|
+
}>) => void;
|
|
39
|
+
answers: Record<string, string>;
|
|
40
|
+
setAnswer: (id: string, v: string) => void;
|
|
41
|
+
busy: boolean;
|
|
42
|
+
error: string;
|
|
43
|
+
submit(): Promise<void>;
|
|
44
|
+
waitlistEnabled: boolean;
|
|
45
|
+
waitlisted: boolean;
|
|
46
|
+
joinWaitlist(typeId?: string): Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
export type EventCheckoutState = ReturnType<typeof useEventCheckout>;
|