@rivil-solutions/site-kit 0.0.0-stage → 0.1.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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -2
  3. package/bin/rivil.mjs +118 -0
  4. package/blocks/booking/block.json +7 -0
  5. package/blocks/booking/files/src/components/rivil/BookingForm.tsx +187 -0
  6. package/blocks/booking/files/src/pages/programare.astro +18 -0
  7. package/blocks/careers/block.json +7 -0
  8. package/blocks/careers/files/src/components/rivil/ApplyForm.tsx +62 -0
  9. package/blocks/careers/files/src/pages/cariere/[job].astro +49 -0
  10. package/blocks/careers/files/src/pages/cariere/index.astro +32 -0
  11. package/blocks/events/block.json +7 -0
  12. package/blocks/events/files/src/components/rivil/EventCheckout.tsx +93 -0
  13. package/blocks/events/files/src/pages/evenimente/[code].astro +35 -0
  14. package/blocks/events/files/src/pages/evenimente/comanda.astro +36 -0
  15. package/blocks/events/files/src/pages/evenimente/index.astro +30 -0
  16. package/blocks/newsletter/block.json +4 -0
  17. package/blocks/newsletter/files/src/components/rivil/Newsletter.astro +35 -0
  18. package/blocks/reviews/block.json +7 -0
  19. package/blocks/reviews/files/src/components/rivil/ReviewForm.tsx +73 -0
  20. package/blocks/reviews/files/src/pages/recenzii.astro +39 -0
  21. package/blocks/stay/block.json +7 -0
  22. package/blocks/stay/files/src/components/rivil/StayBooking.tsx +121 -0
  23. package/blocks/stay/files/src/pages/rezervare.astro +11 -0
  24. package/blocks/ui/block.json +1 -0
  25. package/blocks/ui/files/src/components/rivil/ui.tsx +99 -0
  26. package/blocks/ui/files/src/styles/rivil-blocks.css +47 -0
  27. package/dist/account.d.ts +84 -0
  28. package/dist/account.js +104 -0
  29. package/dist/astro-image.d.ts +29 -0
  30. package/dist/astro-image.js +12 -0
  31. package/dist/client.d.ts +58 -0
  32. package/dist/client.js +153 -0
  33. package/dist/consent.d.ts +6 -0
  34. package/dist/consent.js +10 -0
  35. package/dist/content.d.ts +93 -0
  36. package/dist/content.js +85 -0
  37. package/dist/i18n.d.ts +30 -0
  38. package/dist/i18n.js +69 -0
  39. package/dist/images.d.ts +13 -0
  40. package/dist/images.js +26 -0
  41. package/dist/index.d.ts +13 -0
  42. package/dist/index.js +13 -0
  43. package/dist/modules.d.ts +288 -0
  44. package/dist/modules.js +49 -0
  45. package/dist/proxy.d.ts +47 -0
  46. package/dist/proxy.js +82 -0
  47. package/dist/react/index.d.ts +6 -0
  48. package/dist/react/index.js +6 -0
  49. package/dist/react/texts.d.ts +17 -0
  50. package/dist/react/texts.js +28 -0
  51. package/dist/react/useApplication.d.ts +67 -0
  52. package/dist/react/useApplication.js +94 -0
  53. package/dist/react/useBooking.d.ts +81 -0
  54. package/dist/react/useBooking.js +151 -0
  55. package/dist/react/useEventCheckout.d.ts +48 -0
  56. package/dist/react/useEventCheckout.js +104 -0
  57. package/dist/react/useReview.d.ts +58 -0
  58. package/dist/react/useReview.js +69 -0
  59. package/dist/react/useStay.d.ts +82 -0
  60. package/dist/react/useStay.js +105 -0
  61. package/dist/seo.d.ts +27 -0
  62. package/dist/seo.js +36 -0
  63. package/dist/shop.d.ts +111 -0
  64. package/dist/shop.js +167 -0
  65. package/dist/visitor.d.ts +7 -0
  66. package/dist/visitor.js +17 -0
  67. package/dist/web.d.ts +83 -0
  68. package/dist/web.js +131 -0
  69. package/dist/webhook.d.ts +20 -0
  70. package/dist/webhook.js +39 -0
  71. package/package.json +68 -4
  72. package/themes/aer.css +12 -0
  73. package/themes/cabana.css +12 -0
  74. package/themes/curte.css +12 -0
  75. package/themes/lumen.css +12 -0
  76. package/themes/miez.css +12 -0
  77. package/themes/solvar.css +12 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rivil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,110 @@
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
+ The client for the Rivil site API (`/api/site/v1`), for Astro sites (or any Node server) built on top of Rivil ERP.
4
+ It runs on the server only: the site key never reaches the 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('en')
13
+ const page = await content.one('page', 'about', 'en')
14
+ ```
15
+
16
+ To start a new site, use the starter: [rivil-site-template](https://github.com/iorpaul3/rivil-site-template).
17
+
18
+ ## What's inside
19
+
20
+ - `createSiteClient`: requests with the site key. Reads (`get`) are cached in memory (fresh for 60 s, then served stale and refreshed in the background), identical requests are merged, and `purge()` refreshes everything after a webhook. ERP errors come as `RivilApiError` (`status`, `code`, `message`).
21
+ - `createContentApi`: the Site module (settings, menus, redirects, terms, entries, search, forms).
22
+ - `createModulesApi`: public reads of the modules (booking, careers, reviews, events) for server-rendered pages.
23
+ - `siteProxy` + `MODULE_ROUTES`: the browser calls `/api/rivil/<module>/...` on the site, and the site calls the ERP with the key. Only visitor actions get through.
24
+ - `@rivil-solutions/site-kit/web`: what also runs in the browser (`rivilFetch`, `SiteError`, money, days, consents, `bookingPlan`).
25
+ - `@rivil-solutions/site-kit/react`: the logic of the module forms, with no styling (`useBooking`, `useStay`, `useApplication`, `useReview`, `useEventCheckout`).
26
+ - `rivilWebhookHandler` / `verifyRivilSignature`: signed webhooks (`X-Rivil-Signature`).
27
+ - `visitorIp` + the `X-Rivil-Client-IP` header: ERP rate limits apply per visitor, not per site.
28
+ - `createI18n`: the language from the URL prefix (`/en/...`), `t()`, `lp()`, translated segments, prefixed internal links.
29
+ - `imageAt`, `imageWidths` and `@rivil-solutions/site-kit/astro-image`: Gallery images at the right width, with no processing on the server.
30
+ - `sitemapXml`, `robotsTxt`, `matchRedirect`: SEO and the redirects set in the ERP.
31
+ - `consentScriptUrl`: the Rivil Consent banner.
32
+ - `createShopApi`: the shop (catalog, cart, shipping, checkout, customer account, gift cards, returns), with the language in the URL and `purgeChanged` for the `shop.changed` webhook.
33
+ - `accountProxy` + `AUTH_ROUTES`: the customer account (portal) through the site, with the session in an httpOnly cookie and only the allowed routes.
34
+ - The `rivil` CLI: copies module pages and starting themes into a site (see below).
35
+
36
+ ## Modules on a site
37
+
38
+ ```
39
+ npx rivil list
40
+ npx rivil add booking events
41
+ npx rivil theme cabana
42
+ ```
43
+
44
+ `rivil add` copies the module's pages and styled components into the site. From then on they belong to the site and can be changed freely. The logic (free slots, holds, validation, submitting) stays in this package and is updated with it. The command also prints the scopes the site key needs and the English URL segments to add to `site.config.ts`.
45
+
46
+ Modules: `booking`, `stay`, `careers`, `reviews`, `events`, `newsletter`. Themes: `aer`, `cabana`, `curte`, `lumen`, `miez`, `solvar`.
47
+
48
+ The components call the site, never the ERP directly, through this route:
49
+
50
+ ```ts
51
+ // src/pages/api/rivil/[...path].ts
52
+ import { siteProxy } from '@rivil-solutions/site-kit'
53
+ import { client, siteUrl } from '../../../lib/rivil'
54
+
55
+ // origins: behind a reverse proxy, Astro sees the request on localhost
56
+ const proxy = siteProxy({ client, origins: [siteUrl()] })
57
+ export const ALL = (c) => proxy({ request: c.request, path: c.params.path, clientAddress: c.clientAddress })
58
+ ```
59
+
60
+ ## Shop
61
+
62
+ ```ts
63
+ import { createShopApi, createSiteClient } from '@rivil-solutions/site-kit'
64
+
65
+ const client = createSiteClient({ url: process.env.ERP_URL!, key: process.env.SHOP_CHANNEL_KEY!, visitorIp: () => ipStore.getStore() })
66
+ export const shop = createShopApi(client, { lang: () => i18n.lang() })
67
+
68
+ // shop.changed webhook: shop.purgeChanged(event.data.object)
69
+ ```
70
+
71
+ ## Customer account
72
+
73
+ ```ts
74
+ // src/pages/api/account/[...path].ts
75
+ import { AUTH_ROUTES, accountProxy, createSiteClient } from '@rivil-solutions/site-kit'
76
+
77
+ const proxy = accountProxy({
78
+ client: createSiteClient({ url: process.env.ERP_URL!, key: process.env.ERP_PORTAL_KEY! }),
79
+ cookie: 'site_session',
80
+ routes: [...AUTH_ROUTES, { method: 'GET', path: /^me$/, session: true }, { method: 'PATCH', path: /^me$/, session: true, changes: true }],
81
+ })
82
+ export const ALL = (c) => proxy({ request: c.request, path: c.params.path, cookies: c.cookies, clientAddress: c.clientAddress })
83
+ ```
84
+
85
+ ## Webhook
86
+
87
+ ```ts
88
+ // src/pages/api/hooks/rivil.ts
89
+ import { rivilWebhookHandler } from '@rivil-solutions/site-kit'
90
+ import { rivil } from '../../../lib/rivil'
91
+
92
+ export const POST = ({ request }) => rivilWebhookHandler(process.env.ERP_WEBHOOK_SECRET!, (e) => {
93
+ if (e.type.startsWith('content.')) rivil.purge()
94
+ })(request)
95
+ ```
96
+
97
+ ## Images in Astro
98
+
99
+ ```js
100
+ // astro.config.mjs
101
+ export default defineConfig({ image: { service: { entrypoint: '@rivil-solutions/site-kit/astro-image' } } })
102
+ ```
103
+
104
+ ## Development
105
+
106
+ `pnpm test`, `pnpm check`, `pnpm build`. Publishing runs the checks first (`prepublishOnly`).
107
+
108
+ ## License
109
+
110
+ MIT
package/bin/rivil.mjs ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `rivil add <block...>`: copies a module's pages and components into the site (booking, stay, careers...).
4
+ * `rivil theme <name>`: puts a starting theme in `src/styles/theme.css`.
5
+ * Copied files belong to the site and can be changed freely. An existing file is not overwritten without `--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
+ /** The requested blocks plus their dependencies, each once, dependencies first. */
38
+ function withRequires(list) {
39
+ const out = []
40
+ const visit = (n) => {
41
+ if (out.includes(n)) return
42
+ if (!blockNames().includes(n)) die(`No block named "${n}". Blocks: ${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('Run the command in the site folder (the one with package.json and src/).')
63
+ }
64
+
65
+ if (!cmd || cmd === 'help' || flags.has('--help')) {
66
+ say("rivil add <block...> [--force] [--dry-run] adds a module's pages")
67
+ say('rivil theme <name> [--force] puts a starting theme')
68
+ say('rivil list blocks and themes')
69
+ process.exit(0)
70
+ }
71
+
72
+ if (cmd === 'list') {
73
+ say('Blocks:')
74
+ for (const n of blockNames()) if (!meta(n).hidden) say(` ${n.padEnd(12)} ${meta(n).title}`)
75
+ say('Themes:')
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('Name a block: rivil add booking. The list: 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' ? 'exists ' : r.state === 'replaced' ? 'replaced' : 'added '} ${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('(nothing written: --dry-run)')
100
+ if (scopes.size) say(`The site key needs: ${[...scopes].join(', ')} (ERP, Site, the site's page, Keys).`)
101
+ if (pages.length) say(`New pages: ${pages.join(', ')}. Add them to a menu in ERP, Site, Menus.`)
102
+ if (Object.keys(segments).length) say(`URLs in other languages, in src/site.config.ts under 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(`Themes: ${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 already exists: --force replaces it.' : `${r.state} ${r.rel}`)
115
+ process.exit(0)
116
+ }
117
+
118
+ die(`Unknown command: ${cmd}. See: rivil help`)
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "Online booking: services, specialist, time, confirmation",
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": "Careers: open jobs, job page, application with 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": "Events: list, event page, paid tickets, order",
3
+ "requires": ["ui"],
4
+ "scope": "site:events",
5
+ "pages": ["/evenimente"],
6
+ "segments": { "en": { "evenimente": "events" } }
7
+ }