@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
@@ -0,0 +1,93 @@
1
+ import { ticketOnSale, ticketState, useEventCheckout } from '@rivil-solutions/site-kit/react'
2
+ import type { EventDetail } from '@rivil-solutions/site-kit'
3
+ import { money } from '@rivil-solutions/site-kit/web'
4
+
5
+ import { Button, Done, Field, Message, T } from './ui'
6
+
7
+ /** Biletele unui eveniment: alegere, cupon, datele cumpărătorului; plata o face procesatorul firmei, apoi omul ajunge la pagina comenzii. */
8
+ export default function EventCheckout({ event, lang, orderPath, access, invite }: { event: EventDetail; lang: string; orderPath: string; access?: string; invite?: string }) {
9
+ const t = T(lang)
10
+ const c = useEventCheckout({ event, lang, successPath: orderPath, access, invite })
11
+ const price = (n: number) => (n > 0 ? money(n, event.currency, lang) : t('Gratuit', 'Free'))
12
+ if (c.waitlisted) return <Done text={t('Te anunțăm pe email când se eliberează un loc.', 'We will email you when a seat frees up.')} title={t('Ești pe lista de așteptare', 'You are on the waiting list')} />
13
+
14
+ return (
15
+ <form className="rv rv-card" noValidate onSubmit={(e) => { e.preventDefault(); void c.submit() }}>
16
+ <h3>{t('Bilete', 'Tickets')}</h3>
17
+ <ul className="rv-tickets">
18
+ {c.types.map((type) => {
19
+ const state = ticketState(type)
20
+ return (
21
+ <li key={type.id}>
22
+ <span>
23
+ <b>{type.name}</b>
24
+ {type.description && <small className="rv-muted"> {type.description}</small>}
25
+ <br />
26
+ <small className="rv-muted">
27
+ {state === 'soldout' ? t('Epuizat', 'Sold out') : state === 'soon' ? t('Vânzarea începe curând', 'On sale soon') : state === 'closed' ? t('Vânzare închisă', 'Sales closed') : type.left !== null && type.left <= 10 ? t(`Mai sunt ${type.left} locuri`, `${type.left} seats left`) : ''}
28
+ </small>
29
+ </span>
30
+ <span>{price(type.price)}</span>
31
+ {ticketOnSale(type) ? (
32
+ <span className="rv-qty">
33
+ <button aria-label={t('Mai puțin', 'Fewer')} disabled={!c.qty[type.id]} onClick={() => c.change(type, (c.qty[type.id] ?? 0) - 1)} type="button">-</button>
34
+ <output aria-live="polite">{c.qty[type.id] ?? 0}</output>
35
+ <button aria-label={t('Mai mult', 'More')} onClick={() => c.change(type, (c.qty[type.id] ?? 0) + 1)} type="button">+</button>
36
+ </span>
37
+ ) : state === 'soldout' && c.waitlistEnabled && type.price === 0 ? (
38
+ <button className="rv-option" onClick={() => void c.joinWaitlist(type.id)} style={{ width: 'auto' }} type="button">{t('Listă de așteptare', 'Waiting list')}</button>
39
+ ) : (
40
+ <span />
41
+ )}
42
+ </li>
43
+ )
44
+ })}
45
+ </ul>
46
+
47
+ {c.subtotal > 0 && (
48
+ <div className="rv-actions">
49
+ <input aria-label={t('Cod de reducere', 'Discount code')} maxLength={40} onChange={(e) => c.setCoupon(e.target.value)} placeholder={t('Cod de reducere', 'Discount code')} style={{ maxWidth: 260 }} value={c.coupon} />
50
+ <Button busy={c.busy} disabled={!c.coupon} onClick={() => void c.applyCoupon()} type="button">{t('Aplică', 'Apply')}</Button>
51
+ </div>
52
+ )}
53
+ {c.couponError && <Message>{c.couponError}</Message>}
54
+
55
+ <div className="rv-grid">
56
+ <Field htmlFor="ev-name" label={t('Numele tău', 'Your name')} required>
57
+ <input autoComplete="name" id="ev-name" onChange={(e) => c.setBuyer({ name: e.target.value })} value={c.buyer.name} />
58
+ </Field>
59
+ <Field htmlFor="ev-email" label="Email" required>
60
+ <input autoComplete="email" id="ev-email" onChange={(e) => c.setBuyer({ email: e.target.value })} type="email" value={c.buyer.email} />
61
+ </Field>
62
+ <Field htmlFor="ev-phone" label={t('Telefon', 'Phone')}>
63
+ <input autoComplete="tel" id="ev-phone" onChange={(e) => c.setBuyer({ phone: e.target.value })} type="tel" value={c.buyer.phone} />
64
+ </Field>
65
+ {c.questions.map((q) => (
66
+ <Field htmlFor={`ev-${q.id}`} key={q.id} label={q.label} required={q.required} wide={q.type === 'textarea'}>
67
+ {q.type === 'select' ? (
68
+ <select id={`ev-${q.id}`} onChange={(e) => c.setAnswer(q.id, e.target.value)} value={c.answers[q.id] ?? ''}>
69
+ <option value="">-</option>
70
+ {q.options.map((o) => <option key={o}>{o}</option>)}
71
+ </select>
72
+ ) : q.type === 'textarea' ? (
73
+ <textarea id={`ev-${q.id}`} onChange={(e) => c.setAnswer(q.id, e.target.value)} value={c.answers[q.id] ?? ''} />
74
+ ) : q.type === 'checkbox' ? (
75
+ <input checked={!!c.answers[q.id]} id={`ev-${q.id}`} onChange={(e) => c.setAnswer(q.id, e.target.checked ? 'da' : '')} type="checkbox" />
76
+ ) : (
77
+ <input id={`ev-${q.id}`} onChange={(e) => c.setAnswer(q.id, e.target.value)} value={c.answers[q.id] ?? ''} />
78
+ )}
79
+ </Field>
80
+ ))}
81
+ </div>
82
+
83
+ <div className="rv-actions rv-total">
84
+ <span>
85
+ {c.discount > 0 && <small className="rv-muted">{t('Reducere', 'Discount')}: -{price(c.discount)} · </small>}
86
+ <b>Total: {price(c.total)}</b>
87
+ </span>
88
+ <Button busy={c.busy} type="submit">{c.total > 0 ? t('Plătește', 'Pay') : t('Înscrie-mă', 'Register')}</Button>
89
+ </div>
90
+ {c.error && <Message>{c.error}</Message>}
91
+ </form>
92
+ )
93
+ }
@@ -0,0 +1,35 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import EventCheckout from '@/components/rivil/EventCheckout'
4
+ import NotFound from '@/components/NotFound.astro'
5
+ import { lang, lp, modules, t } from '@/lib/rivil'
6
+
7
+ /** Pagina unui eveniment, cu locurile de acum. `?access=` deschide biletele ascunse, `?invite=` locul ținut din lista de așteptare. */
8
+ const sp = Astro.url.searchParams
9
+ const access = sp.get('access') ?? undefined
10
+ const invite = sp.get('invite') ?? undefined
11
+ const e = await modules.events.get(Astro.params.code ?? '', { lang: lang(), access, invite }).catch(() => null)
12
+ if (!e) Astro.response.status = 404
13
+ Astro.response.headers.set('Cache-Control', 'no-store')
14
+ const when = (iso: string, timeZone: string) => new Intl.DateTimeFormat(lang(), { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric', hour: '2-digit', minute: '2-digit', timeZone }).format(new Date(iso))
15
+ ---
16
+ {e ? (
17
+ <Base title={e.title} description={e.summary} image={e.imageUrl}>
18
+ <article class="wrap entry">
19
+ <p><a href={lp('/evenimente')}>{t('Toate evenimentele', 'All events')}</a></p>
20
+ <h1>{e.title}</h1>
21
+ <p class="lead">{when(e.startsAt, e.timezone)}{e.venueName && ` · ${e.venueName}`}</p>
22
+ {e.venueAddress && <p class="muted">{e.venueAddress}</p>}
23
+ {e.imageUrl && <img class="hero" alt="" src={e.imageUrl} />}
24
+ {e.description && <div class="prose" set:html={e.description} />}
25
+ {e.state === 'open' ? (
26
+ <div style="margin-top:32px">
27
+ <EventCheckout access={access} client:load event={e} invite={invite} lang={lang()} orderPath={lp('/evenimente/comanda')} />
28
+ </div>
29
+ ) : (
30
+ <p><b>{e.state === 'cancelled' ? t('Evenimentul a fost anulat.', 'This event was cancelled.') : t('Evenimentul s-a încheiat.', 'This event has ended.')}</b></p>
31
+ )}
32
+ {e.cancellationPolicy && <p class="muted" style="margin-top:24px">{e.cancellationPolicy}</p>}
33
+ </article>
34
+ </Base>
35
+ ) : <NotFound />}
@@ -0,0 +1,36 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import NotFound from '@/components/NotFound.astro'
4
+ import { lang, lp, modules, t } from '@/lib/rivil'
5
+
6
+ /** Comanda de bilete, după `?order_token=` (întoarcerea de la plată sau linkul din email). */
7
+ const token = Astro.url.searchParams.get('order_token') ?? ''
8
+ const order = /^[A-Za-z0-9_.-]{10,200}$/.test(token) ? await modules.events.order(token, lang()).catch(() => null) : null
9
+ if (!order) Astro.response.status = 404
10
+ Astro.response.headers.set('Cache-Control', 'no-store')
11
+ const status: Record<string, [string, string]> = {
12
+ paid: ['Comanda e confirmată. Biletele au plecat pe email.', 'Your order is confirmed. The tickets were emailed to you.'],
13
+ reserved: ['Locurile sunt rezervate până la plată.', 'Your seats are reserved until payment.'],
14
+ cancelled: ['Comanda a fost anulată.', 'This order was cancelled.'],
15
+ refunded: ['Comanda a fost rambursată.', 'This order was refunded.'],
16
+ }
17
+ const amount = (n: number, currency: string) => new Intl.NumberFormat(lang(), { style: 'currency', currency, maximumFractionDigits: 2 }).format(n)
18
+ ---
19
+ {order ? (
20
+ <Base title={t('Comanda ta', 'Your order')} noindex>
21
+ <section class="wrap entry">
22
+ <h1>{order.event.title}</h1>
23
+ <p class="lead">{t(...(status[order.status] ?? [order.status, order.status]))}</p>
24
+ {order.lateWithoutSeats && <p><b>{t('Plata a ajuns după ce locurile s-au ocupat; banii se întorc pe card.', 'The payment arrived after the seats were taken; the money is refunded to your card.')}</b></p>}
25
+ {order.paymentUrl && <p><a class="btn" href={order.paymentUrl}>{t('Plătește acum', 'Pay now')}</a></p>}
26
+ <ul>
27
+ {order.tickets.map((x) => <li>{x.typeName}, {x.attendeeName} (#{x.number})</li>)}
28
+ </ul>
29
+ <p>Total: <b>{amount(order.total, order.currency)}</b></p>
30
+ {order.status === 'paid' && order.tickets.length > 0 && (
31
+ <p><a class="btn" href={`/api/rivil/events/orders/${encodeURIComponent(token)}/pdf`} data-nolang>{t('Descarcă biletele (PDF)', 'Download tickets (PDF)')}</a></p>
32
+ )}
33
+ <p><a href={lp('/evenimente')}>{t('Alte evenimente', 'More events')}</a></p>
34
+ </section>
35
+ </Base>
36
+ ) : <NotFound />}
@@ -0,0 +1,30 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import { lang, lp, modules, t } from '@/lib/rivil'
4
+
5
+ const events = await modules.events.list(lang()).catch(() => [])
6
+ const when = (iso: string, timeZone: string) => new Intl.DateTimeFormat(lang(), { weekday: 'long', day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit', timeZone }).format(new Date(iso))
7
+ const from = (n: number | null, currency: string) => (n === null ? '' : n > 0 ? t('de la ', 'from ') + new Intl.NumberFormat(lang(), { style: 'currency', currency, maximumFractionDigits: 0 }).format(n) : t('Gratuit', 'Free'))
8
+ ---
9
+ <Base title={t('Evenimente', 'Events')}>
10
+ <section class="wrap">
11
+ <h1>{t('Evenimente', 'Events')}</h1>
12
+ {events.length ? (
13
+ <div class="grid">
14
+ {events.map((e) => (
15
+ <a class="card" href={lp(`/evenimente/${e.code}`)}>
16
+ {e.imageUrl && <img alt="" loading="lazy" src={e.imageUrl} />}
17
+ <div class="card-body">
18
+ <h2>{e.title}</h2>
19
+ <p>{when(e.startsAt, e.timezone)}</p>
20
+ <p>{[e.venueName, from(e.fromPrice, e.currency)].filter(Boolean).join(' · ')}</p>
21
+ {e.state === 'cancelled' && <p><b>{t('Anulat', 'Cancelled')}</b></p>}
22
+ </div>
23
+ </a>
24
+ ))}
25
+ </div>
26
+ ) : (
27
+ <p class="muted">{t('Nu sunt evenimente programate acum.', 'There are no upcoming events right now.')}</p>
28
+ )}
29
+ </section>
30
+ </Base>
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "Abonare la noutăți, cu confirmare pe email",
3
+ "scope": "site:newsletter"
4
+ }
@@ -0,0 +1,35 @@
1
+ ---
2
+ import { lang, t } from '@/lib/rivil'
3
+
4
+ /** Abonarea la noutăți: ERP-ul trimite emailul de confirmare; omul apare în listă abia după ce apasă butonul din email. Se pune în orice pagină sau în subsol. */
5
+ const consent = t('Sunt de acord să primesc noutăți pe email. Mă pot dezabona oricând.', 'I agree to receive news by email. I can unsubscribe at any time.')
6
+ ---
7
+ <form class="form" data-rivil-newsletter data-lang={lang()} novalidate>
8
+ <label>Email<input name="email" type="email" autocomplete="email" required /></label>
9
+ <label class="check"><input name="consent" type="checkbox" required /> <span data-consent>{consent}</span></label>
10
+ <input name="website" tabindex="-1" autocomplete="off" class="hp" aria-hidden="true" />
11
+ <button class="btn" type="submit">{t('Mă abonez', 'Subscribe')}</button>
12
+ <p class="form-status" role="status" hidden></p>
13
+ </form>
14
+
15
+ <script>
16
+ for (const form of document.querySelectorAll<HTMLFormElement>('[data-rivil-newsletter]')) {
17
+ const en = form.dataset.lang !== 'ro'
18
+ const status = form.querySelector<HTMLElement>('.form-status')!
19
+ form.addEventListener('submit', async (e) => {
20
+ e.preventDefault()
21
+ if (!form.reportValidity()) return
22
+ const data = new FormData(form)
23
+ const res = await fetch('/api/rivil/newsletter', {
24
+ method: 'POST',
25
+ headers: { 'content-type': 'application/json' },
26
+ body: JSON.stringify({ email: data.get('email'), website: data.get('website'), lang: form.dataset.lang, consent_text: form.querySelector('[data-consent]')?.textContent }),
27
+ }).catch(() => null)
28
+ const out = await res?.json().catch(() => ({}))
29
+ status.hidden = false
30
+ status.classList.toggle('error', !res?.ok)
31
+ status.textContent = res?.ok ? (en ? 'Check your inbox to confirm.' : 'Verifică emailul și confirmă abonarea.') : out?.error?.message || (en ? 'Please try again.' : 'Încearcă din nou.')
32
+ if (res?.ok) form.reset()
33
+ })
34
+ }
35
+ </script>
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "Recenzii: recenziile publicate și formularul de recenzie",
3
+ "requires": ["ui"],
4
+ "scope": "site:reviews",
5
+ "pages": ["/recenzii"],
6
+ "segments": { "en": { "recenzii": "reviews" } }
7
+ }
@@ -0,0 +1,73 @@
1
+ import { useReview } from '@rivil-solutions/site-kit/react'
2
+ import type { ReviewSurvey } from '@rivil-solutions/site-kit'
3
+
4
+ import { Button, Consents, Done, Field, Message, Pills, T, Trap } from './ui'
5
+
6
+ /** Recenzia deschisă: întrebările vin din chestionarul general al firmei (ERP, Recenzii). */
7
+ export default function ReviewForm({ survey, lang }: { survey: ReviewSurvey; lang: string }) {
8
+ const t = T(lang)
9
+ const r = useReview({ survey, lang })
10
+ const tx = (k: string, ro: string, en: string) => (lang === 'ro' ? (r.texts[k] ?? ro) : en)
11
+ if (r.done !== null) return <Done text={r.done} title={t('Mulțumim!', 'Thank you!')} />
12
+ if (!r.questions.length) return null
13
+
14
+ return (
15
+ <form className="rv rv-card" noValidate onSubmit={(e) => { e.preventDefault(); void r.submit() }}>
16
+ <h3>{tx('form.titleOpen', 'Cum a fost experiența ta?', 'How was your experience?')}</h3>
17
+ {r.questions.map((q) => {
18
+ const v = r.answers[q.id]
19
+ const set = (x: unknown) => r.setAnswer(q.id, x)
20
+ const range = (from: number, to: number) => Array.from({ length: to - from + 1 }, (_, i) => ({ value: from + i, label: from + i }))
21
+ return (
22
+ <Field help={q.help} key={q.id} label={q.label} required={q.required}>
23
+ {q.type === 'nps' && <Pills label={q.label} onChange={set} options={range(0, 10)} value={v as number} />}
24
+ {(q.type === 'stars' || q.type === 'scale' || q.type === 'emoji') && <Pills label={q.label} onChange={set} options={range(1, q.scaleMax || 5).map((o) => ({ ...o, label: q.type === 'stars' ? '★'.repeat(o.value) : o.label }))} value={v as number} />}
25
+ {(q.low || q.high) && (
26
+ <small className="rv-actions rv-muted">
27
+ <span>{q.low}</span>
28
+ <span>{q.high}</span>
29
+ </small>
30
+ )}
31
+ {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} />}
32
+ {(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[]} />}
33
+ {q.type === 'aspects' &&
34
+ (q.options ?? []).map((o) => (
35
+ <div className="rv-actions" key={o}>
36
+ <span>{o}</span>
37
+ <Pills label={o} onChange={(n) => set({ ...((v as Record<string, number>) ?? {}), [o]: n })} options={range(1, 5)} value={(v as Record<string, number> | undefined)?.[o]} />
38
+ </div>
39
+ ))}
40
+ {q.type === 'text' && <input maxLength={300} onChange={(e) => set(e.target.value)} value={String(v ?? '')} />}
41
+ {q.type === 'longtext' && <textarea maxLength={2000} onChange={(e) => set(e.target.value)} value={String(v ?? '')} />}
42
+ </Field>
43
+ )
44
+ })}
45
+ <div className="rv-grid">
46
+ {r.fields.name?.on && (
47
+ <Field htmlFor="rf-name" label={t('Numele tău', 'Your name')} required={r.fields.name.required}>
48
+ <input autoComplete="name" id="rf-name" onChange={(e) => r.setName(e.target.value)} value={r.name} />
49
+ </Field>
50
+ )}
51
+ {r.fields.email?.on && (
52
+ <Field htmlFor="rf-email" label="Email" required={r.fields.email.required}>
53
+ <input autoComplete="email" id="rf-email" onChange={(e) => r.setEmail(e.target.value)} type="email" value={r.email} />
54
+ </Field>
55
+ )}
56
+ {r.fields.service?.on && r.services.length > 0 && (
57
+ <Field htmlFor="rf-service" label={t('Serviciu', 'Service')}>
58
+ <select id="rf-service" onChange={(e) => r.setService(e.target.value)} value={r.service}>
59
+ <option value="">-</option>
60
+ {r.services.map((s) => <option key={s.id} value={s.id}>{s.name}</option>)}
61
+ </select>
62
+ </Field>
63
+ )}
64
+ </div>
65
+ <Consents accepted={r.accepted} items={r.consents} onChange={r.setAccepted} />
66
+ <Trap onChange={r.setTrap} value={r.trap} />
67
+ {r.error && <Message>{r.error}</Message>}
68
+ <div>
69
+ <Button busy={r.busy} type="submit">{tx('form.submit', 'Trimite', 'Submit')}</Button>
70
+ </div>
71
+ </form>
72
+ )
73
+ }
@@ -0,0 +1,39 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import ReviewForm from '@/components/rivil/ReviewForm'
4
+ import { lang, lp, modules, t } from '@/lib/rivil'
5
+
6
+ import '@/styles/rivil-blocks.css'
7
+
8
+ /** Recenziile publicate (ERP, Recenzii, Perete) și formularul de recenzie. `?pagina=` dă paginile următoare. */
9
+ const page = Math.max(0, Number(Astro.url.searchParams.get('pagina')) - 1 || 0)
10
+ const [wall, survey] = await Promise.all([modules.reviews.wall({ lang: lang(), page }).catch(() => null), modules.reviews.survey(lang()).catch(() => null)])
11
+ const stars = (n: number) => '★'.repeat(Math.round(n)) + '☆'.repeat(5 - Math.round(n))
12
+ const date = (iso: string) => new Date(iso).toLocaleDateString(lang(), { day: 'numeric', month: 'long', year: 'numeric' })
13
+ ---
14
+ <Base title={t('Recenzii', 'Reviews')}>
15
+ <section class="wrap rv">
16
+ <h1>{t('Recenzii', 'Reviews')}</h1>
17
+ {wall && wall.count > 0 && wall.average !== null && (
18
+ <p class="lead"><span class="rv-stars">{stars(wall.average)}</span> {wall.average.toFixed(1)} / 5 · {t(`${wall.count} recenzii`, `${wall.count} reviews`)}</p>
19
+ )}
20
+ {wall && wall.reviews.length > 0 && (
21
+ <div class="rv-reviews">
22
+ {wall.reviews.map((r) => (
23
+ <article class="rv-review">
24
+ <span class="rv-stars" aria-label={`${r.score} / 5`}>{stars(r.score)}</span>
25
+ <blockquote>{r.comment}</blockquote>
26
+ <small class="rv-muted">{[r.author, r.service, date(r.iso)].filter(Boolean).join(' · ')}</small>
27
+ {r.reply && <p class="rv-reply">{r.reply.text}</p>}
28
+ </article>
29
+ ))}
30
+ </div>
31
+ )}
32
+ {wall?.hasMore && <p><a class="btn" href={lp(`/recenzii?pagina=${page + 2}`)}>{t('Mai multe recenzii', 'More reviews')}</a></p>}
33
+ {survey && (
34
+ <div style="margin-top:32px">
35
+ <ReviewForm client:visible lang={lang()} survey={survey} />
36
+ </div>
37
+ )}
38
+ </section>
39
+ </Base>
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "Cazare: camere libere pe nopți, rezervare",
3
+ "requires": ["ui"],
4
+ "scope": "site:stay",
5
+ "pages": ["/rezervare"],
6
+ "segments": { "en": { "rezervare": "book" } }
7
+ }
@@ -0,0 +1,121 @@
1
+ import { useStay } from '@rivil-solutions/site-kit/react'
2
+ import { money } from '@rivil-solutions/site-kit/web'
3
+
4
+ import { Button, Done, Field, Message, T } from './ui'
5
+
6
+ /** Rezervarea de cazare: camerele libere și prețurile vin din ERP (Cazare), pe nopțile alese. */
7
+ export default function StayBooking({ lang, currency = 'RON' }: { lang: string; currency?: string }) {
8
+ const t = T(lang)
9
+ const s = useStay({ lang })
10
+ const sum = (n: number) => money(Math.round(n), currency, lang)
11
+
12
+ if (s.booked)
13
+ return (
14
+ <Done title={t('Rezervare confirmată', 'Booking confirmed')} text={t(`Numărul rezervării: ${s.booked.number}.`, `Booking number: ${s.booked.number}.`)}>
15
+ <p>
16
+ {s.booked.typeName}, {s.booked.checkIn} - {s.booked.checkOut}, {sum(s.booked.total)}
17
+ </p>
18
+ {s.booked.transfer && <p style={{ whiteSpace: 'pre-line' }}>{s.booked.transfer.instructions}</p>}
19
+ <Button onClick={s.reset} type="button">{t('Altă rezervare', 'Make another booking')}</Button>
20
+ </Done>
21
+ )
22
+
23
+ return (
24
+ <div className="rv">
25
+ <form className="rv-card" onSubmit={(e) => { e.preventDefault(); void s.search() }}>
26
+ <div className="rv-grid">
27
+ <Field htmlFor="st-in" label={t('Sosire', 'Check-in')}>
28
+ <input id="st-in" onChange={(e) => s.setDates(e.target.value, s.checkOut)} type="date" value={s.checkIn} />
29
+ </Field>
30
+ <Field htmlFor="st-out" label={t('Plecare', 'Check-out')}>
31
+ <input id="st-out" min={s.checkIn} onChange={(e) => s.setDates(s.checkIn, e.target.value)} type="date" value={s.checkOut} />
32
+ </Field>
33
+ <Field htmlFor="st-ad" label={t('Adulți', 'Adults')}>
34
+ <input id="st-ad" max={12} min={1} onChange={(e) => s.setAdults(Number(e.target.value))} type="number" value={s.adults} />
35
+ </Field>
36
+ <Field htmlFor="st-ch" label={t('Copii', 'Children')}>
37
+ <input id="st-ch" max={8} min={0} onChange={(e) => s.setChildren(Number(e.target.value))} type="number" value={s.children} />
38
+ </Field>
39
+ </div>
40
+ <div>
41
+ <Button busy={s.searching} type="submit">{t('Caută', 'Search')}</Button>
42
+ </div>
43
+ {s.error && !s.picked && <Message>{s.error}</Message>}
44
+ </form>
45
+
46
+ {s.rooms && s.rooms.length === 0 && <p className="rv-muted">{t('Nu sunt camere libere în perioada aleasă.', 'No rooms are free for these dates.')}</p>}
47
+
48
+ {s.rooms && !s.picked && (
49
+ <div className="rv-rooms">
50
+ {s.rooms.map((r) => {
51
+ const free = r.freeUnits > 0 && r.total !== null
52
+ return (
53
+ <article className="rv-room" key={r.typeId}>
54
+ {r.type.photoUrls?.[0] && <img alt="" loading="lazy" src={`${r.type.photoUrls[0]}?size=thumb`} />}
55
+ <div>
56
+ <h3>{r.name}</h3>
57
+ {r.type.shortDescription && <p className="rv-muted">{r.type.shortDescription}</p>}
58
+ <p className="rv-muted">
59
+ {[r.type.maxAdults && t(`${r.type.maxAdults} adulți`, `${r.type.maxAdults} adults`), r.type.areaM2 && `${r.type.areaM2} m²`, r.type.beds].filter(Boolean).join(' · ')}
60
+ </p>
61
+ <div className="rv-actions" style={{ marginTop: 'auto' }}>
62
+ {free ? (
63
+ <span>
64
+ <b>{sum(r.total!)}</b>
65
+ <br />
66
+ <small className="rv-muted">{t(`${s.nights} nopți, ${sum(r.average!)} / noapte`, `${s.nights} nights, ${sum(r.average!)} / night`)}</small>
67
+ </span>
68
+ ) : (
69
+ <span className="rv-muted">{r.reason ?? t('Indisponibil', 'Not available')}</span>
70
+ )}
71
+ <Button disabled={!free} onClick={() => s.pick(r)} type="button">{t('Alege', 'Choose')}</Button>
72
+ </div>
73
+ </div>
74
+ </article>
75
+ )
76
+ })}
77
+ </div>
78
+ )}
79
+
80
+ {s.picked && (
81
+ <form className="rv-card" noValidate onSubmit={(e) => { e.preventDefault(); void s.reserve() }}>
82
+ <div className="rv-actions">
83
+ <div>
84
+ <h3>{s.picked.name}</h3>
85
+ <p className="rv-muted">
86
+ {s.checkIn} - {s.checkOut}
87
+ {s.picked.total !== null && `, ${sum(s.picked.total)}`}
88
+ </p>
89
+ </div>
90
+ <button className="rv-option" onClick={() => s.pick(null)} style={{ width: 'auto' }} type="button">{t('Altă cameră', 'Change room')}</button>
91
+ </div>
92
+ <div className="rv-grid">
93
+ <Field htmlFor="st-name" label={t('Nume complet', 'Full name')} required>
94
+ <input autoComplete="name" id="st-name" onChange={(e) => s.setGuest({ name: e.target.value })} value={s.guest.name} />
95
+ </Field>
96
+ <Field htmlFor="st-email" label="Email" required>
97
+ <input autoComplete="email" id="st-email" onChange={(e) => s.setGuest({ email: e.target.value })} type="email" value={s.guest.email} />
98
+ </Field>
99
+ <Field htmlFor="st-phone" label={t('Telefon', 'Phone')} required>
100
+ <input autoComplete="tel" id="st-phone" onChange={(e) => s.setGuest({ phone: e.target.value })} type="tel" value={s.guest.phone} />
101
+ </Field>
102
+ {s.methods.length > 1 && (
103
+ <Field htmlFor="st-pay" label={t('Plata', 'Payment')}>
104
+ <select id="st-pay" onChange={(e) => s.setMethod(e.target.value)} value={s.method}>
105
+ {s.methods.map((m) => <option key={m.method} value={m.method}>{m.label}</option>)}
106
+ </select>
107
+ </Field>
108
+ )}
109
+ <Field htmlFor="st-notes" label={t('Observații', 'Notes')} wide>
110
+ <textarea id="st-notes" onChange={(e) => s.setGuest({ notes: e.target.value })} value={s.guest.notes} />
111
+ </Field>
112
+ </div>
113
+ {s.error && <Message>{s.error}</Message>}
114
+ <div>
115
+ <Button busy={s.busy} type="submit">{t('Confirmă rezervarea', 'Confirm booking')}</Button>
116
+ </div>
117
+ </form>
118
+ )}
119
+ </div>
120
+ )
121
+ }
@@ -0,0 +1,11 @@
1
+ ---
2
+ import Base from '@/layouts/Base.astro'
3
+ import StayBooking from '@/components/rivil/StayBooking'
4
+ import { lang, t } from '@/lib/rivil'
5
+ ---
6
+ <Base title={t('Rezervă o cameră', 'Book a room')}>
7
+ <section class="wrap">
8
+ <h1>{t('Rezervă o cameră', 'Book a room')}</h1>
9
+ <StayBooking client:load lang={lang()} />
10
+ </section>
11
+ </Base>
@@ -0,0 +1 @@
1
+ { "title": "Componentele comune ale formularelor", "hidden": true }
@@ -0,0 +1,99 @@
1
+ import * as React from 'react'
2
+ import { consentParts } from '@rivil-solutions/site-kit/web'
3
+
4
+ import '@/styles/rivil-blocks.css'
5
+
6
+ /** Textul în limba paginii: `T(lang)('Română', 'English')`. */
7
+ export const T = (lang: string) => (ro: string, en: string) => (lang === 'ro' ? ro : en)
8
+
9
+ export function Field({ label, required, help, htmlFor, children, wide }: { label: React.ReactNode; required?: boolean; help?: string; htmlFor?: string; children: React.ReactNode; wide?: boolean }) {
10
+ return (
11
+ <div className={`rv-field${wide ? ' rv-wide' : ''}`}>
12
+ <label htmlFor={htmlFor}>
13
+ {label}
14
+ {required && <span aria-hidden="true"> *</span>}
15
+ </label>
16
+ {children}
17
+ {help && <small className="rv-help">{help}</small>}
18
+ </div>
19
+ )
20
+ }
21
+
22
+ export function Message({ kind = 'error', children }: { kind?: 'error' | 'ok'; children: React.ReactNode }) {
23
+ return (
24
+ <p className={`rv-msg rv-${kind}`} role={kind === 'error' ? 'alert' : 'status'}>
25
+ {children}
26
+ </p>
27
+ )
28
+ }
29
+
30
+ export function Done({ title, text, children }: { title: string; text?: string | null; children?: React.ReactNode }) {
31
+ return (
32
+ <div className="rv-done" role="status">
33
+ <h3>{title}</h3>
34
+ {text && <p>{text}</p>}
35
+ {children}
36
+ </div>
37
+ )
38
+ }
39
+
40
+ /** Consimțământ cu linkurile lui, fără HTML venit din ERP. */
41
+ export function ConsentText({ text }: { text: string }) {
42
+ return (
43
+ <span>
44
+ {consentParts(text).map((p, i) =>
45
+ p.href ? (
46
+ <a href={p.href} key={i} rel="noopener" target="_blank">
47
+ {p.text}
48
+ </a>
49
+ ) : (
50
+ <React.Fragment key={i}>{p.text}</React.Fragment>
51
+ ),
52
+ )}
53
+ </span>
54
+ )
55
+ }
56
+
57
+ export function Consents({ items, accepted, onChange }: { items: Array<{ key: string; text: string; required?: boolean }>; accepted: Record<string, boolean>; onChange: (key: string, v: boolean) => void }) {
58
+ return (
59
+ <>
60
+ {items.map((c) => (
61
+ <label className="rv-check" key={c.key}>
62
+ <input checked={!!accepted[c.key]} onChange={(e) => onChange(c.key, e.target.checked)} required={c.required} type="checkbox" />
63
+ <ConsentText text={c.text} />
64
+ </label>
65
+ ))}
66
+ </>
67
+ )
68
+ }
69
+
70
+ /** O alegere dintr-o listă scurtă, ca butoane (da/nu, o notă, variante). Cu `multi`, valoarea e o listă. */
71
+ export function Pills<V extends string | number>({ options, value, onChange, multi, label }: { options: Array<{ value: V; label: React.ReactNode }>; value: V | V[] | undefined; onChange: (v: V | V[]) => void; multi?: boolean; label: string }) {
72
+ const list = Array.isArray(value) ? value : value === undefined ? [] : [value]
73
+ return (
74
+ <div aria-label={label} className="rv-pills" role="group">
75
+ {options.map((o) => {
76
+ const on = list.includes(o.value)
77
+ return (
78
+ <button aria-pressed={on} key={String(o.value)} onClick={() => onChange(multi ? (on ? list.filter((x) => x !== o.value) : [...list, o.value]) : o.value)} type="button">
79
+ {o.label}
80
+ </button>
81
+ )
82
+ })}
83
+ </div>
84
+ )
85
+ }
86
+
87
+ /** Câmpul capcană pentru roboți: ascuns, rămâne gol la oameni. */
88
+ export function Trap({ value, onChange }: { value: string; onChange: (v: string) => void }) {
89
+ return <input aria-hidden="true" autoComplete="off" className="rv-trap" name="website" onChange={(e) => onChange(e.target.value)} tabIndex={-1} value={value} />
90
+ }
91
+
92
+ export function Button({ busy, children, ...rest }: React.ButtonHTMLAttributes<HTMLButtonElement> & { busy?: boolean }) {
93
+ return (
94
+ <button className="btn" disabled={busy || rest.disabled} {...rest}>
95
+ {busy && <span aria-hidden="true" className="rv-spin" />}
96
+ {children}
97
+ </button>
98
+ )
99
+ }