Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions web/src/components/ReservationReview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from "react";
import { appConfig } from "../config";

export default function ReservationReview({ turnoId, slug, receiptToken, sessionToken }: {
turnoId: string;
slug: string;
receiptToken: string;
sessionToken?: string;
}) {
const [rating, setRating] = React.useState(0);
const [comment, setComment] = React.useState("");
const [saving, setSaving] = React.useState(false);
const [submitted, setSubmitted] = React.useState(false);
const [error, setError] = React.useState("");

async function submit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!rating || saving) return;
setSaving(true);
setError("");
try {
const headers = new Headers({ "Content-Type": "application/json" });
if (receiptToken) headers.set("x-receipt-token", receiptToken);
else if (sessionToken) headers.set("Authorization", `Bearer ${sessionToken}`);
const response = await fetch(`${appConfig.apiUrl}/turnos/publico/${encodeURIComponent(turnoId)}/resena?slug=${encodeURIComponent(slug)}`, {
method: "POST",
headers,
body: JSON.stringify({ puntuacion: rating, comentario: comment }),
referrerPolicy: "no-referrer",
});
const data = await response.json();
if (!response.ok || !data.success) {
setError(data.error || "No pudimos publicar la reseña. Volvé a intentar.");
return;
}
setSubmitted(true);
} catch {
setError("No pudimos publicar la reseña. Volvé a intentar.");
} finally {
setSaving(false);
}
}

if (submitted) return <div className="receipt-review" role="status">
<h2>Gracias por dejar tu reseña</h2>
<a href={`/${encodeURIComponent(slug)}#bl-reviews`}>Ver reseñas del prestador</a>
</div>;

return <form className="receipt-review" onSubmit={submit}>
<h2>Dejá una reseña</h2>
<p>Tu calificación y tu comentario serán públicos en la página del prestador.</p>
<fieldset disabled={saving}>
<legend>Calificación</legend>
<div className="receipt-review-stars">
{[1, 2, 3, 4, 5].map(value => <label key={value}>
<input type="radio" name="reservation-rating" value={value} checked={rating === value} onChange={() => setRating(value)} required aria-label={`${value} ${value === 1 ? "estrella" : "estrellas"}`} />
<span aria-hidden="true">{value <= rating ? "★" : "☆"}</span>
</label>)}
</div>
</fieldset>
<label htmlFor="reservation-review-comment">Comentario (opcional)</label>
<textarea id="reservation-review-comment" rows={3} maxLength={1000} value={comment} onChange={event => setComment(event.target.value)} disabled={saving} />
{error && <p className="receipt-error" role="alert">{error}</p>}
<button type="submit" disabled={!rating || saving}>{saving ? "Publicando…" : "Publicar reseña"}</button>
</form>;
}
4 changes: 2 additions & 2 deletions web/src/pages/BusinessLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export default function BusinessLanding() {
<span>{address.map((line, i) => <React.Fragment key={i}>{i > 0 && <br />}{line}</React.Fragment>)}</span>
</a>
)}
{reviews.cantidad >= 5 && reviewItems.length > 0 && <a className="bl-info-item bl-reviews" href="#bl-reviews" aria-label={`${reviews.cantidad} reseñas, calificación ${reviews.promedio.toLocaleString("es-AR")} de 5`}>
{reviewItems.length > 0 && <a className="bl-info-item bl-reviews" href="#bl-reviews" aria-label={`${reviews.cantidad} reseñas, calificación ${reviews.promedio.toLocaleString("es-AR")} de 5`}>
<strong className="bl-review-score">{reviews.promedio.toLocaleString("es-AR")}</strong>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m12 2.500 2.900 6 6.600.8-4.900 4.500 1.300 6.500L12 17l-5.900 3.300 1.300-6.500L2.500 9.300l6.600-.8z" /></svg>
<span>{reviews.cantidad} {reviews.cantidad === 1 ? "reseña" : "reseñas"}</span>
Expand Down Expand Up @@ -524,7 +524,7 @@ export default function BusinessLanding() {
)} />
</section>}

{reviews.cantidad >= 5 && reviewItems.length > 0 && <section id="bl-reviews" className="bl-section bl-reviews-section"><div className="bl-section-heading"><div><h2>Lo dicen quienes ya vinieron</h2><p>{reviews.promedio.toLocaleString("es-AR")} de 5 · {reviews.cantidad} reseñas</p></div></div><div className="bl-review-list">{reviewItems.map(review => <motion.article className="bl-review" key={review.id} initial={reduceMotion ? false : { opacity: .65, x: 14 }} whileInView={{ opacity: 1, x: 0 }} viewport={{ once: false, amount: .3 }} transition={{ duration: reduceMotion ? 0 : .28 }}><div className="bl-stars" aria-label={`${review.puntuacion} de 5 estrellas`}>{"★".repeat(Math.max(0, Math.min(5, Number(review.puntuacion))))}</div>{review.comentario && <p>“{review.comentario}”</p>}<strong>{review.nombre}</strong></motion.article>)}</div></section>}
{reviewItems.length > 0 && <section id="bl-reviews" className="bl-section bl-reviews-section"><div className="bl-section-heading"><div><h2>Reseñas de clientes</h2><p>{reviews.promedio.toLocaleString("es-AR")} de 5 · {reviews.cantidad} {reviews.cantidad === 1 ? "reseña" : "reseñas"}</p></div></div><div className="bl-review-list">{reviewItems.map(review => <motion.article className="bl-review" key={review.id} initial={reduceMotion ? false : { opacity: .65, x: 14 }} whileInView={{ opacity: 1, x: 0 }} viewport={{ once: false, amount: .3 }} transition={{ duration: reduceMotion ? 0 : .28 }}><div className="bl-stars" aria-label={`${review.puntuacion} de 5 estrellas`}>{"★".repeat(Math.max(0, Math.min(5, Number(review.puntuacion))))}</div>{review.comentario && <p>“{review.comentario}”</p>}<strong>{review.nombre}</strong></motion.article>)}</div></section>}

<section className="bl-final-cta"><h2>¿Ya sabés cuándo venís?</h2><p>Elegí el servicio y reservá en pocos pasos.</p><Link to={`/agenda/${enc}`}>Encontrar mi turno</Link></section>

Expand Down
18 changes: 18 additions & 0 deletions web/src/pages/Receipt.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,21 @@
.receipt-loading{color:#52624c}.receipt-error{color:#a52920;overflow-wrap:anywhere}
.receipt-header a:focus-visible{outline:2px solid #1b6b1a;outline-offset:4px}
@media(max-width:480px){.receipt-header{height:68px}.receipt-main{padding:16px 16px 40px}.receipt-content>h1{font-size:25px}}

.receipt-review{display:grid;gap:14px;padding:clamp(18px,5vw,28px);background:#fff;border:1px solid #dfe8da;border-radius:18px;text-align:left}
.receipt-review h2,.receipt-review p{margin:0}
.receipt-review h2{font-size:22px;letter-spacing:-.4px}
.receipt-review>p:not(.receipt-error){font-size:14px;line-height:1.5;color:#52624c}
.receipt-review fieldset{min-width:0;margin:0;padding:0;border:0}
.receipt-review legend,.receipt-review>label{font-size:14px;font-weight:600}
.receipt-review-stars{display:flex;gap:2px;margin-top:4px}
.receipt-review-stars label{position:relative;display:grid;place-items:center;width:44px;height:44px;cursor:pointer}
.receipt-review-stars input{position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer}
.receipt-review-stars span{display:grid;place-items:center;width:100%;height:100%;border-radius:8px;color:#1b6b1a;font-size:30px}
.receipt-review-stars input:focus-visible+span{outline:2px solid #1b6b1a;outline-offset:-2px}
.receipt-review textarea{box-sizing:border-box;width:100%;padding:10px;border:1px solid #aab8a5;border-radius:8px;font:inherit;resize:vertical}
.receipt-review button{padding:12px;border:0;border-radius:9px;background:#1b6b1a;color:#fff;font:inherit;font-weight:600;cursor:pointer}
.receipt-review button:disabled{background:#e3eae0;color:#52624c;cursor:default}
.receipt-review a,.receipt-details summary{color:#1b6b1a;font-weight:600}
.receipt-details{margin-top:20px}
.receipt-details summary{width:max-content;margin:0 auto 16px;cursor:pointer}
23 changes: 16 additions & 7 deletions web/src/pages/Receipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import { Link, useLocation, useNavigate } from "react-router";
import { appConfig } from "../config";
import BookingReceipt from "../components/BookingReceipt";
import ReservationReview from "../components/ReservationReview";
import { receiptHome } from "../shared/booking-receipt.js";
import "./Receipt.css";

Expand Down Expand Up @@ -44,8 +45,9 @@ export default function Receipt({ failed = false }: { failed?: boolean }) {
if (!response.ok || !data.success || !data.turno || (id && data.turno.id !== id)) throw new Error("Reserva no disponible");
if (controller.signal.aborted) return;
latest = data.turno; misses = 0;
setSnapshot({ key: requestKey, turno: latest, turnos: data.turnos }); setError(""); setLoading(false);
setSnapshot({ key: requestKey, turno: latest, turnos: data.turnos, puedeResenar: data.puede_resenar === true }); setError(""); setLoading(false);
if ((reservationState(latest) === "pending" || latest.pago_estado === "pendiente") && ++polls < 60) timer = window.setTimeout(load, 5000);
else if (Number.isFinite(data.resena_en_ms) && data.resena_en_ms > 0) timer = window.setTimeout(load, Math.min(data.resena_en_ms, 2_147_483_647));
} catch {
if (controller.signal.aborted) return;
if (++misses < 10) timer = window.setTimeout(load, 5000);
Expand All @@ -68,12 +70,8 @@ export default function Receipt({ failed = false }: { failed?: boolean }) {
else if (paymentId) params.set("payment_id", paymentId);
navigate(`${destination}?${params}`, { replace: true });
}, [state, turno?.id, slug, paymentId, receiptToken, location.pathname, navigate]);
return <div className="receipt-page">
<header className="receipt-header"><Link to={home} aria-label="Turnits, volver al inicio"><img src="/assets/browse/LogoTurnitsCompletoB.png" alt="Turnits" /></Link></header>
<main className="receipt-main"><section className="receipt-content" aria-labelledby="receipt-title">
<h1 id="receipt-title">Tu Comprobante</h1>
{loading && <p role="status" className="receipt-loading">Estamos consultando la información de tu reserva.</p>}
{error && <p role="alert" className="receipt-error">{error}</p>}
const showReview = state === "confirmed" && snapshot?.puedeResenar && ["/success", "/sucess"].includes(location.pathname);
const receipt = <>
{Array.isArray(snapshot?.turnos) && snapshot.turnos.length > 1 && <div style={{marginBottom:20,padding:18,background:"#fff",border:"1px solid #e5e7eb",borderRadius:16}}>
<h2 style={{fontSize:18,margin:"0 0 12px"}}>Tus {snapshot.turnos.length} turnos</h2>
{snapshot.turnos.map((item:any)=><div key={item.id} style={{padding:"10px 0",borderTop:"1px solid #e5e7eb"}}>
Expand All @@ -84,6 +82,17 @@ export default function Receipt({ failed = false }: { failed?: boolean }) {
{turno && (Array.isArray(snapshot?.turnos) && snapshot.turnos.length > 1
? snapshot.turnos.map((item:any)=><div key={item.id} style={{marginBottom:20}}><BookingReceipt turno={{...item,slug:item.slug || slug}} /></div>)
: <BookingReceipt turno={{ ...turno, slug: turno.slug || slug }} />)}
</>;
return <div className="receipt-page">
<header className="receipt-header"><Link to={home} aria-label="Turnits, volver al inicio"><img src="/assets/browse/LogoTurnitsCompletoB.png" alt="Turnits" /></Link></header>
<main className="receipt-main"><section className="receipt-content" aria-labelledby="receipt-title">
<h1 id="receipt-title">{showReview ? "Reserva confirmada" : "Tu comprobante"}</h1>
{loading && <p role="status" className="receipt-loading">Estamos consultando la información de tu reserva.</p>}
{error && <p role="alert" className="receipt-error">{error}</p>}
{showReview ? <>
<ReservationReview key={requestKey} turnoId={turno.id} slug={slug} receiptToken={receiptToken} sessionToken={selectStoredSession()?.token} />
<details className="receipt-details"><summary>Ver comprobante</summary>{receipt}</details>
</> : receipt}
</section></main>
</div>;
}