@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.
Files changed (76) hide show
  1. package/README.md +97 -2
  2. package/bin/rivil.mjs +118 -0
  3. package/blocks/booking/block.json +7 -0
  4. package/blocks/booking/files/src/components/rivil/BookingForm.tsx +187 -0
  5. package/blocks/booking/files/src/pages/programare.astro +18 -0
  6. package/blocks/careers/block.json +7 -0
  7. package/blocks/careers/files/src/components/rivil/ApplyForm.tsx +62 -0
  8. package/blocks/careers/files/src/pages/cariere/[job].astro +49 -0
  9. package/blocks/careers/files/src/pages/cariere/index.astro +32 -0
  10. package/blocks/events/block.json +7 -0
  11. package/blocks/events/files/src/components/rivil/EventCheckout.tsx +93 -0
  12. package/blocks/events/files/src/pages/evenimente/[code].astro +35 -0
  13. package/blocks/events/files/src/pages/evenimente/comanda.astro +36 -0
  14. package/blocks/events/files/src/pages/evenimente/index.astro +30 -0
  15. package/blocks/newsletter/block.json +4 -0
  16. package/blocks/newsletter/files/src/components/rivil/Newsletter.astro +35 -0
  17. package/blocks/reviews/block.json +7 -0
  18. package/blocks/reviews/files/src/components/rivil/ReviewForm.tsx +73 -0
  19. package/blocks/reviews/files/src/pages/recenzii.astro +39 -0
  20. package/blocks/stay/block.json +7 -0
  21. package/blocks/stay/files/src/components/rivil/StayBooking.tsx +121 -0
  22. package/blocks/stay/files/src/pages/rezervare.astro +11 -0
  23. package/blocks/ui/block.json +1 -0
  24. package/blocks/ui/files/src/components/rivil/ui.tsx +99 -0
  25. package/blocks/ui/files/src/styles/rivil-blocks.css +47 -0
  26. package/dist/account.d.ts +84 -0
  27. package/dist/account.js +104 -0
  28. package/dist/astro-image.d.ts +29 -0
  29. package/dist/astro-image.js +12 -0
  30. package/dist/client.d.ts +58 -0
  31. package/dist/client.js +153 -0
  32. package/dist/consent.d.ts +6 -0
  33. package/dist/consent.js +10 -0
  34. package/dist/content.d.ts +93 -0
  35. package/dist/content.js +85 -0
  36. package/dist/i18n.d.ts +30 -0
  37. package/dist/i18n.js +69 -0
  38. package/dist/images.d.ts +13 -0
  39. package/dist/images.js +26 -0
  40. package/dist/index.d.ts +13 -0
  41. package/dist/index.js +13 -0
  42. package/dist/modules.d.ts +288 -0
  43. package/dist/modules.js +49 -0
  44. package/dist/proxy.d.ts +47 -0
  45. package/dist/proxy.js +82 -0
  46. package/dist/react/index.d.ts +6 -0
  47. package/dist/react/index.js +6 -0
  48. package/dist/react/texts.d.ts +17 -0
  49. package/dist/react/texts.js +28 -0
  50. package/dist/react/useApplication.d.ts +67 -0
  51. package/dist/react/useApplication.js +94 -0
  52. package/dist/react/useBooking.d.ts +81 -0
  53. package/dist/react/useBooking.js +151 -0
  54. package/dist/react/useEventCheckout.d.ts +48 -0
  55. package/dist/react/useEventCheckout.js +104 -0
  56. package/dist/react/useReview.d.ts +58 -0
  57. package/dist/react/useReview.js +69 -0
  58. package/dist/react/useStay.d.ts +82 -0
  59. package/dist/react/useStay.js +105 -0
  60. package/dist/seo.d.ts +27 -0
  61. package/dist/seo.js +36 -0
  62. package/dist/shop.d.ts +111 -0
  63. package/dist/shop.js +167 -0
  64. package/dist/visitor.d.ts +7 -0
  65. package/dist/visitor.js +17 -0
  66. package/dist/web.d.ts +83 -0
  67. package/dist/web.js +131 -0
  68. package/dist/webhook.d.ts +20 -0
  69. package/dist/webhook.js +39 -0
  70. package/package.json +62 -4
  71. package/themes/aer.css +12 -0
  72. package/themes/cabana.css +12 -0
  73. package/themes/curte.css +12 -0
  74. package/themes/lumen.css +12 -0
  75. package/themes/miez.css +12 -0
  76. package/themes/solvar.css +12 -0
package/README.md CHANGED
@@ -1,3 +1,98 @@
1
- # Temporary Holding Version
1
+ # @rivil-solutions/site-kit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Clientul pentru API-ul de site Rivil (`/api/site/v1`), pentru site-uri Astro (sau orice server Node) construite peste Rivil ERP.
4
+ Rulează doar pe server: cheia de site nu ajunge în browser.
5
+
6
+ ```ts
7
+ import { createContentApi, createSiteClient } from '@rivil-solutions/site-kit'
8
+
9
+ export const rivil = createSiteClient({ url: process.env.ERP_URL!, key: process.env.ERP_SITE_KEY! })
10
+ export const content = createContentApi(rivil)
11
+
12
+ const menus = await content.menus('ro')
13
+ const page = await content.one('page', 'despre', 'ro')
14
+ ```
15
+
16
+ ## Ce conține
17
+
18
+ - `createSiteClient`: cereri cu cheia de site; citirile (`get`) stau în memorie (60 s proaspete, apoi servite vechi și reîmprospătate în fundal), cererile identice se unesc, `purge()` reîmprospătează tot după un webhook. Erorile ERP vin ca `RivilApiError` (`status`, `code`, `message`).
19
+ - `createContentApi`: modulul Site (setări, meniuri, redirecturi, termeni, intrări, căutare, formulare).
20
+ - `rivilWebhookHandler` / `verifyRivilSignature`: webhook-urile semnate (`X-Rivil-Signature`).
21
+ - `visitorIp` + antetul `X-Rivil-Client-IP`: limitele din ERP se aplică pe vizitator.
22
+ - `createI18n`: limba din prefixul adresei (`/en/...`), `t()`, `lp()`, segmente traduse, linkuri interne cu prefix.
23
+ - `imageAt`, `imageWidths` și `@rivil-solutions/site-kit/astro-image`: pozele din Galerie la lățimea potrivită, fără prelucrare pe server.
24
+ - `sitemapXml`, `robotsTxt`, `matchRedirect`: SEO și redirecturile din ERP.
25
+ - `consentScriptUrl`: bannerul Rivil Consent.
26
+ - `createShopApi`: magazinul (catalog, coș, livrare, checkout, cont de client, carduri cadou, retururi), cu limba în adresă și `purgeChanged` pentru webhook-ul `shop.changed`.
27
+ - `accountProxy` + `AUTH_ROUTES`: contul de client (portal) prin site, cu sesiunea în cookie httpOnly și doar rutele permise.
28
+
29
+ - `createModulesApi`: citirile publice ale modulelor (programări, cariere, recenzii, evenimente) pentru paginile randate pe server.
30
+ - `siteProxy` + `MODULE_ROUTES`: browserul cheamă `/api/rivil/<modul>/...` pe site, site-ul cheamă ERP-ul cu cheia; trec doar acțiunile unui vizitator.
31
+ - `@rivil-solutions/site-kit/web`: ce rulează și în browser (`rivilFetch`, `SiteError`, sume, zile, consimțăminte, `bookingPlan`).
32
+ - `@rivil-solutions/site-kit/react`: logica formularelor de modul, fără aspect (`useBooking`, `useStay`, `useApplication`, `useReview`, `useEventCheckout`).
33
+ - CLI `rivil`: `rivil add <modul>` copiază în site paginile și componentele unui modul (stilizate, ale site-ului de acum înainte), `rivil theme <nume>` pune un aspect de pornire, `rivil list`.
34
+
35
+ ## Module în site
36
+
37
+ ```ts
38
+ // src/pages/api/rivil/[...path].ts
39
+ import { siteProxy } from '@rivil-solutions/site-kit'
40
+ import { client, siteUrl } from '../../../lib/rivil'
41
+
42
+ // origins: în spatele unui proxy Astro vede cererea pe localhost
43
+ const proxy = siteProxy({ client, origins: [siteUrl()] })
44
+ export const ALL = (c) => proxy({ request: c.request, path: c.params.path, clientAddress: c.clientAddress })
45
+ ```
46
+
47
+ ```
48
+ npx rivil add booking events
49
+ npx rivil theme cabana
50
+ ```
51
+
52
+ ## Magazin
53
+
54
+ ```ts
55
+ import { createShopApi, createSiteClient } from '@rivil-solutions/site-kit'
56
+
57
+ const client = createSiteClient({ url: process.env.ERP_URL!, key: process.env.SHOP_CHANNEL_KEY!, visitorIp: () => ipStore.getStore() })
58
+ export const shop = createShopApi(client, { lang: () => i18n.lang() })
59
+
60
+ // webhook shop.changed: shop.purgeChanged(event.data.object)
61
+ ```
62
+
63
+ ## Cont de client
64
+
65
+ ```ts
66
+ // src/pages/api/account/[...path].ts
67
+ import { AUTH_ROUTES, accountProxy, createSiteClient } from '@rivil-solutions/site-kit'
68
+
69
+ const proxy = accountProxy({
70
+ client: createSiteClient({ url: process.env.ERP_URL!, key: process.env.ERP_PORTAL_KEY! }),
71
+ cookie: 'site_session',
72
+ routes: [...AUTH_ROUTES, { method: 'GET', path: /^me$/, session: true }, { method: 'PATCH', path: /^me$/, session: true, changes: true }],
73
+ })
74
+ export const ALL = (c) => proxy({ request: c.request, path: c.params.path, cookies: c.cookies, clientAddress: c.clientAddress })
75
+ ```
76
+
77
+ ## Webhook
78
+
79
+ ```ts
80
+ // src/pages/api/hooks/rivil.ts
81
+ import { rivilWebhookHandler } from '@rivil-solutions/site-kit'
82
+ import { rivil } from '../../../lib/rivil'
83
+
84
+ export const POST = ({ request }) => rivilWebhookHandler(process.env.ERP_WEBHOOK_SECRET!, (e) => {
85
+ if (e.type.startsWith('content.')) rivil.purge()
86
+ })(request)
87
+ ```
88
+
89
+ ## Imagini în Astro
90
+
91
+ ```js
92
+ // astro.config.mjs
93
+ export default defineConfig({ image: { service: { entrypoint: '@rivil-solutions/site-kit/astro-image' } } })
94
+ ```
95
+
96
+ ## Dezvoltare
97
+
98
+ `pnpm test`, `pnpm check`, `pnpm build`. Publicarea: `npm publish --access public` (rulează întâi verificările).
package/bin/rivil.mjs ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `rivil add <bloc...>`: copiază în site paginile și componentele unui modul (programări, cazare, cariere...).
4
+ * `rivil theme <nume>`: pune un aspect de pornire în `src/styles/theme.css`.
5
+ * Fișierele copiate sunt ale site-ului: se schimbă liber. Unul care există deja nu se suprascrie fără `--force`.
6
+ */
7
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
8
+ import { dirname, join, relative, sep } from 'node:path'
9
+ import { fileURLToPath } from 'node:url'
10
+
11
+ const KIT = join(dirname(fileURLToPath(import.meta.url)), '..')
12
+ const BLOCKS = join(KIT, 'blocks')
13
+ const THEMES = join(KIT, 'themes')
14
+ const cwd = process.cwd()
15
+ const args = process.argv.slice(2)
16
+ const flags = new Set(args.filter((a) => a.startsWith('--')))
17
+ const [cmd, ...names] = args.filter((a) => !a.startsWith('--'))
18
+ const force = flags.has('--force')
19
+ const dry = flags.has('--dry-run')
20
+
21
+ const say = (s = '') => process.stdout.write(`${s}\n`)
22
+ const die = (s) => {
23
+ process.stderr.write(`${s}\n`)
24
+ process.exit(1)
25
+ }
26
+
27
+ const blockNames = () => readdirSync(BLOCKS).filter((n) => existsSync(join(BLOCKS, n, 'block.json'))).sort()
28
+ const meta = (name) => JSON.parse(readFileSync(join(BLOCKS, name, 'block.json'), 'utf8'))
29
+
30
+ function walk(dir) {
31
+ return readdirSync(dir).flatMap((n) => {
32
+ const p = join(dir, n)
33
+ return statSync(p).isDirectory() ? walk(p) : [p]
34
+ })
35
+ }
36
+
37
+ /** Blocurile cerute plus cele de care depind, fiecare o dată, dependențele întâi. */
38
+ function withRequires(list) {
39
+ const out = []
40
+ const visit = (n) => {
41
+ if (out.includes(n)) return
42
+ if (!blockNames().includes(n)) die(`Nu există blocul „${n}”. Blocurile: ${blockNames().filter((x) => !meta(x).hidden).join(', ')}.`)
43
+ for (const r of meta(n).requires ?? []) visit(r)
44
+ out.push(n)
45
+ }
46
+ list.forEach(visit)
47
+ return out
48
+ }
49
+
50
+ function copy(from, to, overwrite = force) {
51
+ const rel = relative(cwd, to).split(sep).join('/')
52
+ const had = existsSync(to)
53
+ if (had && !overwrite) return { rel, state: 'skipped' }
54
+ if (!dry) {
55
+ mkdirSync(dirname(to), { recursive: true })
56
+ writeFileSync(to, readFileSync(from))
57
+ }
58
+ return { rel, state: had ? 'replaced' : 'added' }
59
+ }
60
+
61
+ function needProject() {
62
+ if (!existsSync(join(cwd, 'package.json')) || !existsSync(join(cwd, 'src'))) die('Rulează comanda în folderul site-ului (cel cu package.json și src/).')
63
+ }
64
+
65
+ if (!cmd || cmd === 'help' || flags.has('--help')) {
66
+ say('rivil add <bloc...> [--force] [--dry-run] adaugă paginile unui modul')
67
+ say('rivil theme <nume> [--force] pune un aspect de pornire')
68
+ say('rivil list blocurile și aspectele')
69
+ process.exit(0)
70
+ }
71
+
72
+ if (cmd === 'list') {
73
+ say('Blocuri:')
74
+ for (const n of blockNames()) if (!meta(n).hidden) say(` ${n.padEnd(12)} ${meta(n).title}`)
75
+ say('Aspecte:')
76
+ for (const f of readdirSync(THEMES).filter((f) => f.endsWith('.css'))) say(` ${f.replace(/\.css$/, '')}`)
77
+ process.exit(0)
78
+ }
79
+
80
+ if (cmd === 'add') {
81
+ needProject()
82
+ if (!names.length) die('Spune ce bloc: rivil add booking. Lista: rivil list.')
83
+ const all = withRequires(names)
84
+ const scopes = new Set()
85
+ const pages = []
86
+ const segments = {}
87
+ for (const n of all) {
88
+ const m = meta(n)
89
+ const files = walk(join(BLOCKS, n, 'files'))
90
+ for (const f of files) {
91
+ const r = copy(f, join(cwd, relative(join(BLOCKS, n, 'files'), f)))
92
+ say(`${r.state === 'skipped' ? 'există ' : r.state === 'replaced' ? 'înlocuit' : 'adăugat'} ${r.rel}`)
93
+ }
94
+ if (m.scope) scopes.add(m.scope)
95
+ pages.push(...(m.pages ?? []))
96
+ for (const [l, map] of Object.entries(m.segments ?? {})) Object.assign((segments[l] ??= {}), map)
97
+ }
98
+ say()
99
+ if (dry) say('(nimic scris: --dry-run)')
100
+ if (scopes.size) say(`Cheia de site are nevoie de: ${[...scopes].join(', ')} (ERP, Site, fișa site-ului, Chei).`)
101
+ if (pages.length) say(`Pagini noi: ${pages.join(', ')}. Pune-le în meniu din ERP, Site, Meniuri.`)
102
+ if (Object.keys(segments).length) say(`Adresele în alte limbi, în src/site.config.ts la segments: ${JSON.stringify(segments)}`)
103
+ process.exit(0)
104
+ }
105
+
106
+ if (cmd === 'theme') {
107
+ needProject()
108
+ const name = names[0]
109
+ const file = join(THEMES, `${name}.css`)
110
+ if (!name || !existsSync(file)) die(`Aspectele: ${readdirSync(THEMES).map((f) => f.replace(/\.css$/, '')).join(', ')}.`)
111
+ const to = join(cwd, 'src', 'styles', 'theme.css')
112
+ const blank = existsSync(to) && !readFileSync(to, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').trim()
113
+ const r = copy(file, to, blank)
114
+ say(r.state === 'skipped' ? 'src/styles/theme.css există deja: --force îl înlocuiește.' : `${r.state === 'replaced' ? 'înlocuit' : 'adăugat'} ${r.rel}`)
115
+ process.exit(0)
116
+ }
117
+
118
+ die(`Comandă necunoscută: ${cmd}. Vezi: rivil help`)
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "Programări online: servicii, specialist, oră, confirmare",
3
+ "requires": ["ui"],
4
+ "scope": "site:booking",
5
+ "pages": ["/programare"],
6
+ "segments": { "en": { "programare": "booking" } }
7
+ }
@@ -0,0 +1,187 @@
1
+ import { useBooking } from '@rivil-solutions/site-kit/react'
2
+ import type { BookingCatalog } from '@rivil-solutions/site-kit'
3
+ import { money } from '@rivil-solutions/site-kit/web'
4
+
5
+ import { Button, Consents, Done, Field, Message, T, Trap } from './ui'
6
+
7
+ /** Programarea online: pașii vin din ERP (Programări online), ora aleasă se ține cât se completează datele. */
8
+ export default function BookingForm({ catalog, lang, initialService }: { catalog: BookingCatalog; lang: string; initialService?: string }) {
9
+ const t = T(lang)
10
+ const b = useBooking({ catalog, lang, initialService })
11
+ const price = (n: number | null) => (n == null ? '' : money(n, b.currency, lang))
12
+ const dayLabel = (iso: string) => new Date(`${iso}T12:00`).toLocaleDateString(lang, { weekday: 'short', day: 'numeric', month: 'short' })
13
+ const timeLabel = (iso: string) => iso.slice(11, 16)
14
+ const labels: Record<string, string> = { services: t('Servicii', 'Services'), location: t('Locație', 'Location'), specialist: 'Specialist', time: t('Data și ora', 'Date and time'), details: t('Datele tale', 'Your details') }
15
+
16
+ if (b.done)
17
+ return (
18
+ <Done title={t('Programare făcută', 'Appointment booked')} text={b.done.message}>
19
+ <p>
20
+ <b>{b.chosen.map((s) => s.name).join(' + ')}</b>, {dayLabel(b.done.start.slice(0, 10))} {timeLabel(b.done.start)}
21
+ </p>
22
+ <Button onClick={b.reset} type="button">{t('Altă programare', 'Book another visit')}</Button>
23
+ </Done>
24
+ )
25
+
26
+ const byCategory = b.services.reduce<Record<string, typeof b.services>>((m, s) => ((m[s.category ?? ''] ??= []).push(s), m), {})
27
+
28
+ return (
29
+ <div className="rv">
30
+ <ol className="rv-steps" aria-label={t('Pași', 'Steps')}>
31
+ {b.steps.map((s, i) => (
32
+ <li aria-current={i === b.stepIndex ? 'step' : undefined} key={s}>
33
+ {i + 1}. {labels[s]}
34
+ </li>
35
+ ))}
36
+ </ol>
37
+
38
+ <section className="rv-card">
39
+ {b.step === 'services' && (
40
+ <>
41
+ <h3>{t('Alege serviciile', 'Choose your services')}</h3>
42
+ {Object.entries(byCategory).map(([cat, list]) => (
43
+ <div className="rv-options" key={cat}>
44
+ {cat && <strong className="rv-muted">{cat}</strong>}
45
+ {list.map((s) => (
46
+ <button aria-pressed={b.picked.includes(s.id)} className="rv-option" key={s.id} onClick={() => b.toggle(s.id)} type="button">
47
+ <span>
48
+ {s.name}
49
+ {s.description && <small>{s.description}</small>}
50
+ </span>
51
+ <span>
52
+ {s.durationMinutes} min{s.price != null && <small>{price(s.price)}</small>}
53
+ </span>
54
+ </button>
55
+ ))}
56
+ </div>
57
+ ))}
58
+ </>
59
+ )}
60
+
61
+ {b.step === 'location' && (
62
+ <>
63
+ <h3>{t('Alege locația', 'Choose a location')}</h3>
64
+ <div className="rv-options">
65
+ {b.locations.map((l) => (
66
+ <button aria-pressed={b.locationId === l.id} className="rv-option" key={l.id} onClick={() => { b.chooseLocation(l.id); b.next() }} type="button">
67
+ <span>
68
+ {l.name}
69
+ {l.address && <small>{l.address}</small>}
70
+ </span>
71
+ </button>
72
+ ))}
73
+ </div>
74
+ </>
75
+ )}
76
+
77
+ {b.step === 'specialist' && (
78
+ <>
79
+ <h3>{t('Alege specialistul', 'Choose a specialist')}</h3>
80
+ <div className="rv-options">
81
+ <button aria-pressed={b.employeeId === ''} className="rv-option" onClick={() => { b.chooseEmployee(''); b.next() }} type="button">
82
+ <span>
83
+ {t('Oricare specialist', 'Any specialist')}
84
+ <small>{t('Îți găsim prima oră liberă.', 'We will find you the first free slot.')}</small>
85
+ </span>
86
+ </button>
87
+ {b.employees.map((e) => (
88
+ <button aria-pressed={b.employeeId === e.id} className="rv-option" key={e.id} onClick={() => { b.chooseEmployee(e.id); b.next() }} type="button">
89
+ <span>{e.name}</span>
90
+ </button>
91
+ ))}
92
+ </div>
93
+ </>
94
+ )}
95
+
96
+ {b.step === 'time' && (
97
+ <>
98
+ <h3>{t('Alege data și ora', 'Choose a date and time')}</h3>
99
+ {b.loadingSlots && <p className="rv-muted">{t('Se caută orele libere...', 'Looking for free times...')}</p>}
100
+ {b.slots && b.slots.length === 0 && <p className="rv-muted">{t('Nu sunt ore libere în următoarele săptămâni.', 'No free times in the next weeks.')}</p>}
101
+ {b.byDay.size > 0 && (
102
+ <div className="rv-days">
103
+ {[...b.byDay.keys()].map((d) => (
104
+ <button aria-pressed={b.day === d} className="rv-time" key={d} onClick={() => b.chooseDay(d)} type="button">
105
+ {dayLabel(d)}
106
+ </button>
107
+ ))}
108
+ </div>
109
+ )}
110
+ {b.day && (
111
+ <div className="rv-times">
112
+ {b.daySlots.map((s) => (
113
+ <button aria-pressed={b.slot?.start === s.start} className="rv-time" key={s.start} onClick={() => b.pickSlot(s)} type="button">
114
+ {timeLabel(s.start)}
115
+ </button>
116
+ ))}
117
+ </div>
118
+ )}
119
+ </>
120
+ )}
121
+
122
+ {b.step === 'details' && (
123
+ <form noValidate onSubmit={(e) => { e.preventDefault(); void b.submit() }} className="rv">
124
+ <h3>{t('Datele tale', 'Your details')}</h3>
125
+ <p className="rv-muted">{t(`Ora ta e ținută ${b.holdMinutes} minute.`, `Your time is held for ${b.holdMinutes} minutes.`)}</p>
126
+ <div className="rv-grid">
127
+ {b.fields.map((f) => (
128
+ <Field help={f.help} htmlFor={`bk-${f.key}`} key={f.key} label={f.label} required={f.required} wide={f.type === 'textarea'}>
129
+ {f.type === 'textarea' ? (
130
+ <textarea id={`bk-${f.key}`} onChange={(e) => b.setAnswer(f.key, e.target.value)} placeholder={f.placeholder} value={String(b.answers[f.key] ?? '')} />
131
+ ) : f.type === 'select' ? (
132
+ <select id={`bk-${f.key}`} onChange={(e) => b.setAnswer(f.key, e.target.value)} value={String(b.answers[f.key] ?? '')}>
133
+ <option value="">-</option>
134
+ {(f.options ?? []).map((o) => <option key={o}>{o}</option>)}
135
+ </select>
136
+ ) : f.type === 'checkbox' ? (
137
+ <input checked={!!b.answers[f.key]} id={`bk-${f.key}`} onChange={(e) => b.setAnswer(f.key, e.target.checked)} type="checkbox" />
138
+ ) : (
139
+ <input
140
+ autoComplete={f.type === 'email' ? 'email' : f.type === 'tel' ? 'tel' : f.key === 'name' ? 'name' : undefined}
141
+ id={`bk-${f.key}`}
142
+ onChange={(e) => b.setAnswer(f.key, e.target.value)}
143
+ placeholder={f.placeholder}
144
+ type={['email', 'tel', 'number', 'date'].includes(f.type) ? f.type : 'text'}
145
+ value={String(b.answers[f.key] ?? '')}
146
+ />
147
+ )}
148
+ </Field>
149
+ ))}
150
+ </div>
151
+ <Consents accepted={b.accepted} items={b.consents} onChange={b.setAccepted} />
152
+ <Trap onChange={b.setTrap} value={b.trap} />
153
+ <div>
154
+ <Button busy={b.busy} type="submit">{t('Confirmă programarea', 'Confirm appointment')}</Button>
155
+ </div>
156
+ </form>
157
+ )}
158
+
159
+ {b.error && <Message>{b.error}</Message>}
160
+
161
+ <div className="rv-actions">
162
+ {b.stepIndex > 0 ? <button className="rv-option" style={{ width: 'auto' }} onClick={b.back} type="button">{t('Înapoi', 'Back')}</button> : <span />}
163
+ {b.step === 'services' && (
164
+ <Button disabled={!b.picked.length} onClick={b.next} type="button">{t('Continuă', 'Continue')}</Button>
165
+ )}
166
+ </div>
167
+ </section>
168
+
169
+ {b.chosen.length > 0 && (
170
+ <aside className="rv-card rv-summary">
171
+ <h3>{t('Rezumat', 'Summary')}</h3>
172
+ {b.chosen.map((s) => (
173
+ <div className="rv-actions" key={s.id}>
174
+ <span>{s.name}</span>
175
+ <span>{price(s.price)}</span>
176
+ </div>
177
+ ))}
178
+ {b.slot && <div className="rv-muted">{dayLabel(b.slot.start.slice(0, 10))}, {timeLabel(b.slot.start)}</div>}
179
+ <div className="rv-actions rv-total">
180
+ <span>{b.minutes} min</span>
181
+ <span>{price(b.total)}</span>
182
+ </div>
183
+ </aside>
184
+ )}
185
+ </div>
186
+ )
187
+ }
@@ -0,0 +1,18 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import BookingForm from '@/components/rivil/BookingForm'
4
+ import NotFound from '@/components/NotFound.astro'
5
+ import { lang, modules, t } from '@/lib/rivil'
6
+
7
+ /** Programarea online. `?serviciu=<id>` pornește cu serviciul ales (link de pe pagina serviciului). */
8
+ const catalog = await modules.booking.catalog(lang()).catch(() => null)
9
+ if (!catalog) Astro.response.status = 404
10
+ ---
11
+ {catalog ? (
12
+ <Base title={t('Programare online', 'Book an appointment')}>
13
+ <section class="wrap">
14
+ <h1>{t('Programare online', 'Book an appointment')}</h1>
15
+ <BookingForm catalog={catalog} client:load initialService={Astro.url.searchParams.get('serviciu') ?? undefined} lang={lang()} />
16
+ </section>
17
+ </Base>
18
+ ) : <NotFound />}
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "Cariere: joburi deschise, pagina jobului, aplicare cu CV",
3
+ "requires": ["ui"],
4
+ "scope": "site:careers",
5
+ "pages": ["/cariere"],
6
+ "segments": { "en": { "cariere": "careers" } }
7
+ }
@@ -0,0 +1,62 @@
1
+ import { useApplication } from '@rivil-solutions/site-kit/react'
2
+ import type { ApplyInfo } from '@rivil-solutions/site-kit'
3
+
4
+ import { Button, Consents, Done, Field, Message, Pills, T, Trap } from './ui'
5
+
6
+ /** Aplicarea la un job (sau spontană, fără `job`): câmpurile, întrebările și CV-ul le cere firma din ERP (Cariere). */
7
+ export default function ApplyForm({ info, job, lang }: { info: ApplyInfo; job?: string; lang: string }) {
8
+ const t = T(lang)
9
+ const a = useApplication({ info, job, lang })
10
+ if (a.done !== null) return <Done text={a.done} title={t('Aplicare trimisă', 'Application sent')} />
11
+
12
+ return (
13
+ <form className="rv rv-card" noValidate onSubmit={(e) => { e.preventDefault(); void a.submit() }}>
14
+ <h3>{a.texts['post.apply'] ?? t('Aplică pentru acest post', 'Apply for this position')}</h3>
15
+ <div className="rv-grid">
16
+ <Field htmlFor="ap-name" label={t('Nume complet', 'Full name')} required>
17
+ <input autoComplete="name" id="ap-name" onChange={(e) => a.setName(e.target.value)} value={a.name} />
18
+ </Field>
19
+ <Field htmlFor="ap-email" label="Email" required>
20
+ <input autoComplete="email" id="ap-email" onChange={(e) => a.setEmail(e.target.value)} type="email" value={a.email} />
21
+ </Field>
22
+ {a.textFields.map((f) => (
23
+ <Field htmlFor={`ap-${f.key}`} key={f.key} label={f.label} required={f.required}>
24
+ <input id={`ap-${f.key}`} onChange={(e) => a.setExtra(f.key, e.target.value)} type={f.key === 'start' ? 'date' : 'text'} value={a.extra[f.key] ?? ''} />
25
+ </Field>
26
+ ))}
27
+ {a.longFields.map((f) => (
28
+ <Field htmlFor={`ap-${f.key}`} key={f.key} label={f.label} required={f.required} wide>
29
+ <textarea id={`ap-${f.key}`} onChange={(e) => a.setExtra(f.key, e.target.value)} value={a.extra[f.key] ?? ''} />
30
+ </Field>
31
+ ))}
32
+ {a.cv.on && (
33
+ <Field help={t(`Maximum ${a.cv.maxMb ?? 10} MB.`, `Up to ${a.cv.maxMb ?? 10} MB.`)} htmlFor="ap-cv" label="CV" required={a.cv.required} wide>
34
+ <input accept={a.cvAccept} id="ap-cv" onChange={(e) => a.setFile('cv', e.target.files?.[0])} type="file" />
35
+ </Field>
36
+ )}
37
+ </div>
38
+
39
+ {a.questions.map((q) => {
40
+ const v = a.answers[q.id]
41
+ const set = (x: unknown) => a.setAnswer(q.id, x)
42
+ return (
43
+ <Field help={q.help} key={q.id} label={q.label} required={q.required}>
44
+ {['text', 'url', 'number', 'date'].includes(q.type) && <input onChange={(e) => set(e.target.value)} type={q.type} value={String(v ?? '')} />}
45
+ {q.type === 'longtext' && <textarea onChange={(e) => set(e.target.value)} value={String(v ?? '')} />}
46
+ {q.type === 'yesno' && <Pills label={q.label} onChange={set} options={[{ value: 'yes', label: t('Da', 'Yes') }, { value: 'no', label: t('Nu', 'No') }]} value={v as string} />}
47
+ {(q.type === 'choice' || q.type === 'multi') && <Pills label={q.label} multi={q.type === 'multi'} onChange={set} options={(q.options ?? []).map((o) => ({ value: o, label: o }))} value={v as string | string[]} />}
48
+ {q.type === 'scale' && <Pills label={q.label} onChange={set} options={Array.from({ length: (q.max ?? 5) - (q.min ?? 1) + 1 }, (_, i) => ({ value: (q.min ?? 1) + i, label: (q.min ?? 1) + i }))} value={v as number} />}
49
+ {q.type === 'file' && <input onChange={(e) => a.setFile(q.id, e.target.files?.[0])} type="file" />}
50
+ </Field>
51
+ )
52
+ })}
53
+
54
+ <Consents accepted={a.accepted} items={a.consents} onChange={a.setAccepted} />
55
+ <Trap onChange={a.setTrap} value={a.trap} />
56
+ {a.error && <Message>{a.error}</Message>}
57
+ <div>
58
+ <Button busy={a.busy} type="submit">{a.texts['post.submit'] ?? t('Trimite aplicarea', 'Send application')}</Button>
59
+ </div>
60
+ </form>
61
+ )
62
+ }
@@ -0,0 +1,49 @@
1
+ ---
2
+ import { textToHtml } from '@rivil-solutions/site-kit'
3
+
4
+ import Base from '@/layouts/Base.astro'
5
+ import ApplyForm from '@/components/rivil/ApplyForm'
6
+ import NotFound from '@/components/NotFound.astro'
7
+ import { lang, lp, modules, siteUrl, t } from '@/lib/rivil'
8
+
9
+ const data = await modules.careers.job(Astro.params.job ?? '', lang()).catch(() => null)
10
+ const p = data?.posting
11
+ if (!p) Astro.response.status = 404
12
+ const sections = p
13
+ ? [
14
+ { title: t('Ce vei face', 'What you will do'), html: textToHtml(p.description) },
15
+ { title: t('Ce căutăm', 'What we look for'), html: textToHtml(p.requirements) },
16
+ { title: t('Ce oferim', 'What we offer'), html: textToHtml(p.benefits) },
17
+ ...(p.sections ?? []).map((s) => ({ title: s.title, html: textToHtml(s.body) })),
18
+ ].filter((s) => s.html)
19
+ : []
20
+ const ld = p && JSON.stringify({
21
+ '@context': 'https://schema.org',
22
+ '@type': 'JobPosting',
23
+ title: p.title,
24
+ description: [p.description, p.requirements, p.benefits].filter(Boolean).join('\n\n'),
25
+ datePosted: p.publishedAt?.slice(0, 10),
26
+ validThrough: p.closesAt ?? undefined,
27
+ hiringOrganization: { '@type': 'Organization', sameAs: siteUrl() },
28
+ jobLocation: p.location ? { '@type': 'Place', address: { '@type': 'PostalAddress', addressLocality: p.location } } : undefined,
29
+ }).replace(/</g, '\\u003c')
30
+ ---
31
+ {p ? (
32
+ <Base title={p.seo?.title || p.title} description={p.seo?.description || p.description?.slice(0, 160)}>
33
+ <article class="wrap entry">
34
+ <p><a href={lp('/cariere')}>{t('Toate posturile', 'All positions')}</a></p>
35
+ <h1>{p.title}</h1>
36
+ <p class="lead">{[p.location, p.employmentType, p.workMode, p.salary].filter(Boolean).join(' · ')}</p>
37
+ {sections.map((s) => (
38
+ <section>
39
+ <h2>{s.title}</h2>
40
+ <div class="prose" set:html={s.html} />
41
+ </section>
42
+ ))}
43
+ <div style="margin-top:40px">
44
+ <ApplyForm client:visible info={data!.info} job={p.slug} lang={lang()} />
45
+ </div>
46
+ </article>
47
+ <script is:inline type="application/ld+json" set:html={ld} />
48
+ </Base>
49
+ ) : <NotFound />}
@@ -0,0 +1,32 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import ApplyForm from '@/components/rivil/ApplyForm'
4
+ import { lang, lp, modules, t } from '@/lib/rivil'
5
+
6
+ const [jobs, spontaneous] = await Promise.all([modules.careers.list(lang()).catch(() => []), modules.careers.spontaneous(lang()).catch(() => null)])
7
+ ---
8
+ <Base title={t('Cariere', 'Careers')}>
9
+ <section class="wrap">
10
+ <h1>{t('Cariere', 'Careers')}</h1>
11
+ {jobs.length ? (
12
+ <div class="grid">
13
+ {jobs.map((j) => (
14
+ <a class="card" href={lp(`/cariere/${j.slug}`)}>
15
+ <div class="card-body">
16
+ <h2>{j.title}</h2>
17
+ <p>{[j.location, j.employmentType, j.workMode, j.salary].filter(Boolean).join(' · ')}</p>
18
+ </div>
19
+ </a>
20
+ ))}
21
+ </div>
22
+ ) : (
23
+ <p class="muted">{t('Nu avem posturi deschise acum.', 'There are no open positions right now.')}</p>
24
+ )}
25
+ {spontaneous && (
26
+ <div style="margin-top:48px">
27
+ <h2>{t('Aplicare spontană', 'Spontaneous application')}</h2>
28
+ <ApplyForm client:visible info={spontaneous.info} lang={lang()} />
29
+ </div>
30
+ )}
31
+ </section>
32
+ </Base>
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "Evenimente: lista, pagina evenimentului, bilete cu plată, comanda",
3
+ "requires": ["ui"],
4
+ "scope": "site:events",
5
+ "pages": ["/evenimente"],
6
+ "segments": { "en": { "evenimente": "events" } }
7
+ }