Add reviewed AI drafts and durable staff-approved Gmail delivery
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { useEffect } from 'react';
|
||||
import { api, type Conversation, type Hotel, type Knowledge, type Mailboxes } from './api';
|
||||
|
||||
type Run = (action: () => Promise<void>) => Promise<void>;
|
||||
export function ReplyActions({message,hotel,mailboxes,knowledge,dirty,busy,run,onUpdate}:{message:Conversation;hotel:Hotel;mailboxes:Mailboxes;knowledge:Knowledge[];dirty:boolean;busy:boolean;run:Run;onUpdate:(c:Conversation)=>void}) {
|
||||
const delivery=message.delivery;
|
||||
useEffect(()=>{
|
||||
if(!delivery || !['Pending','Sending'].includes(delivery.state))return;
|
||||
let active=true;
|
||||
const timer=setInterval(()=>{api<Conversation>(`/conversations/${message.id}`).then(c=>{if(active)onUpdate(c);}).catch(()=>{});},5000);
|
||||
return()=>{active=false;clearInterval(timer);};
|
||||
},[message.id,delivery?.state,onUpdate]);
|
||||
const generate=()=>run(async()=>{
|
||||
if(message.draft && !window.confirm('Replace the saved draft with a new AI suggestion?'))return;
|
||||
onUpdate(await api<Conversation>(`/conversations/${message.id}/generate`,'POST',{version:message.version}));
|
||||
});
|
||||
const send=()=>run(async()=>{
|
||||
if(!window.confirm(`Send this saved reply to ${message.replyAddress}?\n\n${message.draft}\n\nThis submits the reply to Gmail. You cannot undo it here.`))return;
|
||||
onUpdate(await api<Conversation>(`/conversations/${message.id}/send`,'POST',{version:message.version,recipient:message.replyAddress}));
|
||||
});
|
||||
const act=(action:string)=>run(async()=>onUpdate(await api<Conversation>(`/conversations/${message.id}/delivery/${action}`,'POST',{version:message.version})));
|
||||
const canSend=hotel.staffSendingEnabled&&mailboxes.sendingConfigured&&mailboxes.items.some(m=>m.id===message.mailboxId&&m.canSend);
|
||||
return <section className="reply-actions" aria-label="Reply review and delivery">
|
||||
{message.draftReviewNote&&<p className="staff-note">AI review: {message.draftReviewNote}</p>}
|
||||
{!!message.draftSources?.length&&<details><summary>Hotel answers referenced by this draft</summary>{message.draftSources.map(id=>{const source=knowledge.find(k=>k.id===id);return <div key={id}><strong>{source?.title||'Answer no longer available'}</strong><p>{source?.answer||'Ask your hotel owner to check this information.'}</p>{source&&!source.approved&&<p>This answer is no longer approved. Check the draft before sending.</p>}</div>;})}</details>}
|
||||
{delivery?<div role="status"><strong>Delivery: {delivery.state==='NeedsReview'?'Needs verification':delivery.state}</strong><p>{delivery.detail}</p><p className="small">To: {delivery.recipient}</p>{delivery.state==='Rejected'&&<button className="button secondary" disabled={busy} onClick={()=>act('retry')}>Retry approved reply</button>}{delivery.state==='NeedsReview'&&<><button className="button secondary" disabled={busy} onClick={()=>act('verify')}>Verify in Gmail Sent</button><p className="small">Reference: {delivery.messageId}. An uncertain reply is never automatically resent.</p></>}</div>:<>
|
||||
<div className="form-actions"><button className="button secondary" disabled={busy||dirty||!hotel.aiDraftsEnabled||!mailboxes.aiConfigured} onClick={generate}>Generate AI draft</button><button className="button primary" disabled={busy||dirty||!canSend||!message.draft.trim()||!message.replyAddress} onClick={send}>Review and send</button></div>
|
||||
<p className="small muted">{dirty?'Save your changes before generating or sending.':canSend?`Reply to: ${message.replyAddress||'Unavailable — open this message in Gmail'}. Sending always requires your approval.`:'Staff sending is not enabled for this mailbox. Your hotel owner can configure it in Settings.'}</p>
|
||||
{!hotel.aiDraftsEnabled&&<p className="small muted">AI drafts are off. Your hotel owner can enable them after the administrator configures AI.</p>}
|
||||
</>}
|
||||
</section>;
|
||||
}
|
||||
|
||||
export function ReplyControls({hotel,mailboxes,owner,busy,run,onSave}:{hotel:Hotel;mailboxes:Mailboxes;owner:boolean;busy:boolean;run:Run;onSave:(hotel:Hotel)=>void}) {
|
||||
const update=(field:'aiDraftsEnabled'|'staffSendingEnabled',value:boolean)=>run(async()=>{
|
||||
if(value&&!window.confirm(field==='aiDraftsEnabled'?'Enable AI drafts? Message text and selected approved hotel answers will be sent to the configured OpenAI service when staff request a draft.':'Enable staff-approved Gmail sending for this hotel? Each reply will still require a staff member to review and approve it.'))return;
|
||||
onSave(await api<Hotel>('/reply-controls','PUT',{version:hotel.version,aiDraftsEnabled:hotel.aiDraftsEnabled,staffSendingEnabled:hotel.staffSendingEnabled,[field]:value}));
|
||||
});
|
||||
return <section className="settings-card"><h2>Reply controls</h2><p>Your team reviews every reply. Automatic replies remain off.</p><label className="checkbox-label"><input type="checkbox" checked={hotel.aiDraftsEnabled||false} disabled={!owner||busy||(!mailboxes.aiConfigured&&!hotel.aiDraftsEnabled)} onChange={e=>update('aiDraftsEnabled',e.target.checked)}/>AI drafts from approved hotel knowledge</label><p className="small muted">{mailboxes.aiConfigured?'Only requested drafts use AI. Check all facts before sending.':'Your administrator must configure the AI API key and model first.'}</p><label className="checkbox-label"><input type="checkbox" checked={hotel.staffSendingEnabled||false} disabled={!owner||busy||(!mailboxes.sendingConfigured&&!hotel.staffSendingEnabled)} onChange={e=>update('staffSendingEnabled',e.target.checked)}/>Allow staff to approve and send replies</label><p className="small muted">{mailboxes.sendingConfigured?'Reconnect Google to grant send permission if it was previously read-only.':'Your administrator must enable Google sending first.'}</p></section>;
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
export type User = { id: string; name: string; role: string; hotelId: string };
|
||||
export type Session = { preview: boolean; csrfToken: string; user: User | null };
|
||||
export type Hotel = { id: string; name: string; timezone: string; signature: string; replyMode: string; version: number };
|
||||
export type Conversation = { id: string; from: string; subject: string; body: string; receivedAt: string; status: string; draft: string; category: string; note: string; providerThreadId: string; version: number };
|
||||
export type Hotel = { id: string; name: string; timezone: string; signature: string; replyMode: string; version: number; aiDraftsEnabled: boolean; staffSendingEnabled: boolean };
|
||||
export type Conversation = { id: string; from: string; subject: string; body: string; receivedAt: string; status: string; draft: string; category: string; note: string; providerThreadId: string; version: number; mailboxId: string; replyAddress: string; draftSources: string[]; draftReviewNote: string; delivery: { state: string; recipient: string; body: string; detail: string; messageId: string; providerId: string } | null };
|
||||
export type Knowledge = { id: string; title: string; category: string; answer: string; keywords: string; approved: boolean; version: number };
|
||||
export type Activity = { id: string; at: string; userName: string; action: string };
|
||||
export type Mailboxes = { configured: boolean; items: { id: string; email: string; status: string; lastSyncAt: string | null; syncError: string }[] };
|
||||
export type Mailboxes = { configured: boolean; aiConfigured?: boolean; sendingConfigured?: boolean; items: { id: string; email: string; status: string; lastSyncAt: string | null; syncError: string; canSend: boolean }[] };
|
||||
let csrf = '';
|
||||
export async function api<T>(path: string, method = 'GET', body?: unknown): Promise<T> {
|
||||
const response = await fetch('/api' + path, { method, credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
|
||||
+6
-5
@@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client';
|
||||
import { Inbox, BookOpen, Settings, Activity as ActivityIcon, Search, ArrowUpRight, ChevronDown, Check, CheckCheck, Clock3, FileText, LogOut, RefreshCw, ArrowLeft, Plus, X, Mail, ShieldCheck, Save, CircleHelp, Building2, ChevronRight } from 'lucide-react';
|
||||
import { api, session, type Session, type Hotel, type Conversation, type Knowledge, type Activity, type Mailboxes } from './api';
|
||||
import './style.css';
|
||||
import { ReplyActions, ReplyControls } from './ReplyActions';
|
||||
|
||||
const labels: Record<string,string> = { NeedsAttention: 'Needs attention', DraftReady: 'Draft ready', Completed: 'Completed' };
|
||||
const initials = (name: string) => name.replace(/<.*>/, '').trim().split(' ').filter(Boolean).slice(0,2).map(x => x[0]).join('').toUpperCase();
|
||||
@@ -39,9 +40,9 @@ function App() {
|
||||
<div className="sidebar-bottom"><div className="mode-card"><ShieldCheck size={20}/><strong>You're in control</strong><p>Replies stay as drafts until your team reviews them.</p></div><div className="profile"><span className="avatar profile-avatar">{initials(auth.user.name)}</span><div><strong>{auth.user.name}</strong><small>{auth.user.role==='Owner'?'Hotel owner':'Team member'}</small></div><button className="icon-button" onClick={logout} disabled={busy} aria-label="Sign out"><LogOut size={18}/></button></div></div>
|
||||
</aside>
|
||||
<main className="main">
|
||||
<header className="topbar"><span><span className="breadcrumb">Workspace</span><ChevronRight size={14}/>{page==='/inbox'?'Inbox':page==='/knowledge'?'Hotel knowledge':page==='/activity'?'Activity':'Settings'}</span><div className="topbar-right">{auth.preview&&<span className="preview-pill">Preview · sample data</span>}<span className="draft-mode"><span/>Draft-only mode</span><button className="icon-button" aria-label="Refresh workspace" disabled={busy} onClick={()=>run(refresh)}><RefreshCw size={17}/></button></div></header>
|
||||
<header className="topbar"><span><span className="breadcrumb">Workspace</span><ChevronRight size={14}/>{page==='/inbox'?'Inbox':page==='/knowledge'?'Hotel knowledge':page==='/activity'?'Activity':'Settings'}</span><div className="topbar-right">{auth.preview&&<span className="preview-pill">Preview · sample data</span>}<span className="draft-mode"><span/>{hotel?.staffSendingEnabled?'Staff-approved sending':'Draft-only mode'}</span><button className="icon-button" aria-label="Refresh workspace" disabled={busy} onClick={()=>run(refresh)}><RefreshCw size={17}/></button></div></header>
|
||||
{errorBox}{notice&&<div className="toast" role="status"><Check size={17}/>{notice}</div>}
|
||||
{!loaded?<div className="loading"><p>Loading your hotel…</p></div>:page==='/inbox'?<InboxPage conversations={conversations} knowledge={knowledge} busy={busy} run={run} onUpdate={c=>setConversations(old=>old.map(x=>x.id===c.id?c:x))} notify={setNotice} go={go}/>:page==='/knowledge'?<KnowledgePage items={knowledge} canEdit={auth.user.role==='Owner'} busy={busy} run={run} onUpdate={item=>setKnowledge(old=>old.some(x=>x.id===item.id)?old.map(x=>x.id===item.id?item:x):[...old,item])} notify={setNotice}/>:page==='/activity'?<div className="page"><PageHeading eyebrow="A clear record" title="Workspace activity" text="Changes made by your team, in one place."/><div className="activity-list">{activity.length?activity.map(a=><div className="activity-row" key={a.id}><span className="activity-icon"><Check size={18}/></span><div><strong>{a.action}</strong><p>{a.userName}</p></div><time>{date(a.at)}</time></div>):<Empty title="No activity yet" text="Changes to your workspace will appear here."/>}</div></div>:<SettingsPage hotel={hotel!} mailboxes={mailboxes} preview={auth.preview} owner={auth.user.role==='Owner'} busy={busy} run={run} onSave={h=>{setHotel(h);setNotice('Hotel settings saved.');}}/>}
|
||||
{!loaded?<div className="loading"><p>Loading your hotel…</p></div>:page==='/inbox'?<InboxPage hotel={hotel!} mailboxes={mailboxes} conversations={conversations} knowledge={knowledge} busy={busy} run={run} onUpdate={c=>setConversations(old=>old.map(x=>x.id===c.id?c:x))} notify={setNotice} go={go}/>:page==='/knowledge'?<KnowledgePage items={knowledge} canEdit={auth.user.role==='Owner'} busy={busy} run={run} onUpdate={item=>setKnowledge(old=>old.some(x=>x.id===item.id)?old.map(x=>x.id===item.id?item:x):[...old,item])} notify={setNotice}/>:page==='/activity'?<div className="page"><PageHeading eyebrow="A clear record" title="Workspace activity" text="Changes made by your team, in one place."/><div className="activity-list">{activity.length?activity.map(a=><div className="activity-row" key={a.id}><span className="activity-icon"><Check size={18}/></span><div><strong>{a.action}</strong><p>{a.userName}</p></div><time>{date(a.at)}</time></div>):<Empty title="No activity yet" text="Changes to your workspace will appear here."/>}</div></div>:<SettingsPage hotel={hotel!} mailboxes={mailboxes} preview={auth.preview} owner={auth.user.role==='Owner'} busy={busy} run={run} onSave={h=>{setHotel(h);setNotice('Hotel settings saved.');}}/>}
|
||||
</main>
|
||||
</div>;
|
||||
}
|
||||
@@ -52,7 +53,7 @@ function Login({preview,onLogin,onPreview,busy,error}:{preview:boolean;onLogin:(
|
||||
return <div className="login-layout"><section className="login-story"><div className="brand"><span className="brand-mark">g</span>guestops.</div><div><span className="eyebrow">A little more time for your guests</span><h1>Great hospitality.<br/>A calmer inbox.</h1><p>Your conversations, hotel knowledge and team.<br/>Together in one thoughtful workspace.</p><div className="login-detail"><Inbox size={24}/><span>Less time sorting emails.<br/><strong>More time making guests feel welcome.</strong></span></div></div><small>Built around the way hotels work.</small></section><section className="login-form"><div><span className="eyebrow">Your hotel workspace</span><h1>Welcome back</h1><p>Sign in to take care of your guests.</p>{error}<form onSubmit={e=>{e.preventDefault();onLogin(email,password);}}><label>Email address<input type="email" autoComplete="username" value={email} onChange={e=>setEmail(e.target.value)} placeholder="you@yourhotel.com" required/></label><label>Password<input type="password" autoComplete="current-password" value={password} onChange={e=>setPassword(e.target.value)} required/></label><button className="button primary wide" disabled={busy}>{busy?'Signing in…':'Sign in'}<ArrowUpRight size={18}/></button></form><p className="small muted">Need access or help signing in? Contact your hotel administrator.</p>{preview&&<div className="preview-login"><span>Explore the interface with sample conversations.</span><button className="button secondary wide" onClick={onPreview} disabled={busy}>Open preview workspace<ArrowUpRight size={17}/></button><small>Preview changes are temporary. No real emails are sent.</small></div>}</div></section></div>;
|
||||
}
|
||||
type Run=(a:()=>Promise<void>)=>Promise<void>;
|
||||
function InboxPage({conversations,knowledge,busy,run,onUpdate,notify,go}:{conversations:Conversation[];knowledge:Knowledge[];busy:boolean;run:Run;onUpdate:(c:Conversation)=>void;notify:(s:string)=>void;go:(s:string)=>void}){
|
||||
function InboxPage({hotel,mailboxes,conversations,knowledge,busy,run,onUpdate,notify,go}:{hotel:Hotel;mailboxes:Mailboxes;conversations:Conversation[];knowledge:Knowledge[];busy:boolean;run:Run;onUpdate:(c:Conversation)=>void;notify:(s:string)=>void;go:(s:string)=>void}){
|
||||
const [filter,setFilter]=useState('All'),[search,setSearch]=useState(''),[selected,setSelected]=useState<string|null>(null),[draft,setDraft]=useState(''),[mobileDetail,setMobileDetail]=useState(false);
|
||||
const filtered=conversations.filter(c=>(filter==='All'||c.status===filter)&&(c.subject+' '+c.from+' '+c.body).toLowerCase().includes(search.toLowerCase()));
|
||||
const current=filtered.find(c=>c.id===selected)||filtered[0];
|
||||
@@ -65,7 +66,7 @@ function InboxPage({conversations,knowledge,busy,run,onUpdate,notify,go}:{conver
|
||||
return <div className="inbox-page"><div className="inbox-heading"><PageHeading eyebrow="A warm welcome starts here" title="Your guest inbox" text={needs?`${needs} conversations need your attention. Let's make their day.`:'A little space to focus on your guests.'}/><div className="mini-stats"><div><strong>{needs}</strong><span>Need attention</span></div><div><strong>{ready}</strong><span>Drafts ready</span></div></div></div>
|
||||
<div className="inbox-toolbar"><div className="tabs" role="group" aria-label="Filter conversations">{[['All','All messages'],['NeedsAttention','Needs attention'],['DraftReady','Drafts'],['Completed','Completed']].map(([key,label])=><button key={key} className={filter===key?'tab selected':'tab'} onClick={()=>{if(current&&draft!==current.draft&&!window.confirm('Discard your unsaved draft changes?'))return;setFilter(key);}}>{label}{key==='NeedsAttention'&&needs>0&&<span>{needs}</span>}</button>)}</div><label className="search"><Search size={17}/><input aria-label="Search conversations" placeholder="Search messages…" value={search} onChange={e=>setSearch(e.target.value)}/></label></div>
|
||||
{!conversations.length?<div className="onboard-empty"><Empty title="A calmer inbox starts here" text="Connect your hotel's Google mailbox to bring recent guest conversations into GuestOps."/><button className="button primary" onClick={()=>go('/settings')}>Connect your mailbox<ArrowUpRight size={17}/></button></div>:<div className={'inbox-panels '+(mobileDetail?'show-detail':'')}><section className="message-list" aria-label="Conversations"><div className="list-title">{filtered.length} conversation{filtered.length===1?'':'s'}<span>Newest first<ChevronDown size={13}/></span></div>{filtered.map((c,i)=><button key={c.id} className={'message-card '+(current?.id===c.id?'current':'')} onClick={()=>select(c)}><div className="message-top"><span className={'avatar tone-'+i%4}>{initials(sender(c.from))}</span><strong>{sender(c.from)}</strong><time>{new Date(c.receivedAt).toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'})}</time></div><h3>{c.subject}</h3><p>{c.body}</p><div className="message-bottom"><span className={'status '+c.status}>{c.status==='DraftReady'?<FileText size={12}/>:c.status==='Completed'?<CheckCheck size={12}/>:<Clock3 size={12}/>} {labels[c.status]}</span><span>{c.category}</span></div></button>)}{!filtered.length&&<Empty title="Nothing here just now" text="Try another filter or search."/>}</section>
|
||||
<section className="conversation" aria-label="Selected conversation">{current?<><div className="conversation-tools"><button className="button text mobile-back" onClick={()=>setMobileDetail(false)}><ArrowLeft size={16}/>Back</button><span className="category-label">{current.category}</span><button className="button secondary compact" onClick={resolve} disabled={busy}><Check size={16}/>{current.status==='Completed'?'Reopen':'Mark complete'}</button></div><div className="conversation-body"><h2>{current.subject}</h2><div className="sender-line"><span className="avatar tone-0">{initials(sender(current.from))}</span><div><strong>{sender(current.from)}</strong><small>To your hotel · {date(current.receivedAt)}</small></div></div><div className="email-body">{current.body}</div>{current.note&&<div className="staff-note"><CircleHelp size={17}/>{current.note}</div>}<div className="reply-box"><div className="reply-header"><span><FileText size={17}/><strong>Your reply draft</strong></span><span className="small muted">Only visible to your team</span></div><label className="sr-only" htmlFor="draft">Reply draft</label><textarea id="draft" value={draft} onChange={e=>setDraft(e.target.value)} placeholder="Write a thoughtful reply…"/><div className="knowledge-insert"><BookOpen size={15}/><select aria-label="Insert an approved hotel answer" value="" onChange={e=>{const k=knowledge.find(x=>x.id===e.target.value);if(k)setDraft(d=>d+(d?'\n\n':'')+k.answer);}}><option value="">Insert an approved hotel answer</option>{knowledge.filter(k=>k.approved).map(k=><option key={k.id} value={k.id}>{k.title}</option>)}</select></div><div className="reply-footer"><span><ShieldCheck size={15}/>No automatic sending</span><button className="button primary" disabled={busy||draft===current.draft} onClick={save}><Save size={16}/>Save draft</button></div></div><div className="below-draft"><span>Review your draft, then reply from your hotel mailbox.</span>{current.providerThreadId&&/^[a-zA-Z0-9]+$/.test(current.providerThreadId)&&<a href={'https://mail.google.com/mail/u/0/#inbox/'+encodeURIComponent(current.providerThreadId)} target="_blank" rel="noopener noreferrer">Open in Gmail<ArrowUpRight size={14}/></a>}</div></div></>:<Empty title="Choose a conversation" text="Read a message and prepare a reply here."/>}</section></div>}</div>;
|
||||
<section className="conversation" aria-label="Selected conversation">{current?<><div className="conversation-tools"><button className="button text mobile-back" onClick={()=>setMobileDetail(false)}><ArrowLeft size={16}/>Back</button><span className="category-label">{current.category}</span><button className="button secondary compact" onClick={resolve} disabled={busy||!!current.delivery&¤t.delivery.state!=='Sent'}><Check size={16}/>{current.status==='Completed'?'Reopen':'Mark complete'}</button></div><div className="conversation-body"><h2>{current.subject}</h2><div className="sender-line"><span className="avatar tone-0">{initials(sender(current.from))}</span><div><strong>{sender(current.from)}</strong><small>To your hotel · {date(current.receivedAt)}</small></div></div><div className="email-body">{current.body}</div>{current.note&&<div className="staff-note"><CircleHelp size={17}/>{current.note}</div>}<div className="reply-box"><div className="reply-header"><span><FileText size={17}/><strong>Your reply draft</strong></span><span className="small muted">Only visible to your team</span></div><label className="sr-only" htmlFor="draft">Reply draft</label><textarea id="draft" disabled={!!current.delivery||busy} value={draft} onChange={e=>setDraft(e.target.value)} placeholder="Write a thoughtful reply…"/><div className="knowledge-insert"><BookOpen size={15}/><select disabled={!!current.delivery||busy} aria-label="Insert an approved hotel answer" value="" onChange={e=>{const k=knowledge.find(x=>x.id===e.target.value);if(k)setDraft(d=>d+(d?'\n\n':'')+k.answer);}}><option value="">Insert an approved hotel answer</option>{knowledge.filter(k=>k.approved).map(k=><option key={k.id} value={k.id}>{k.title}</option>)}</select></div><div className="reply-footer"><span><ShieldCheck size={15}/>No automatic sending</span><button className="button primary" disabled={busy||!!current.delivery||draft===current.draft} onClick={save}><Save size={16}/>Save draft</button></div></div><ReplyActions message={current} hotel={hotel} mailboxes={mailboxes} knowledge={knowledge} dirty={draft!==current.draft} busy={busy} run={run} onUpdate={onUpdate}/><div className="below-draft"><span>Check the reply and recipient before sending.</span>{current.providerThreadId&&/^[a-zA-Z0-9]+$/.test(current.providerThreadId)&&<a href={'https://mail.google.com/mail/u/0/#inbox/'+encodeURIComponent(current.providerThreadId)} target="_blank" rel="noopener noreferrer">Open in Gmail<ArrowUpRight size={14}/></a>}</div></div></>:<Empty title="Choose a conversation" text="Read a message and prepare a reply here."/>}</section></div>}</div>;
|
||||
}
|
||||
function KnowledgePage({items,canEdit,busy,run,onUpdate,notify}:{items:Knowledge[];canEdit:boolean;busy:boolean;run:Run;onUpdate:(k:Knowledge)=>void;notify:(s:string)=>void}){
|
||||
const [edit,setEdit]=useState<Knowledge|null>(null),[search,setSearch]=useState('');
|
||||
@@ -76,6 +77,6 @@ function KnowledgePage({items,canEdit,busy,run,onUpdate,notify}:{items:Knowledge
|
||||
function SettingsPage({hotel,mailboxes,preview,owner,busy,run,onSave}:{hotel:Hotel;mailboxes:Mailboxes;preview:boolean;owner:boolean;busy:boolean;run:Run;onSave:(h:Hotel)=>void}){
|
||||
const [form,setForm]=useState(hotel);useEffect(()=>setForm(hotel),[hotel]);
|
||||
const result=new URLSearchParams(location.search).get('google');
|
||||
return <div className="page settings-page"><PageHeading eyebrow="Make yourself at home" title="Hotel settings" text="The details that make this workspace yours."/>{result&&<div className={result==='connected'?'success-note':'alert'} role="status">{result==='connected'?'Google mailbox connected. Recent messages will appear after synchronization.':result==='cancelled'?'Google connection was cancelled.':'Google connection could not be completed. Try again or contact your administrator.'}</div>}<section className="settings-card"><div className="section-heading"><Building2 size={20}/><div><h2>Your hotel</h2><p>Shared with everyone in this workspace.</p></div></div><form onSubmit={e=>{e.preventDefault();run(async()=>onSave(await api<Hotel>('/hotel','PUT',form)));}}><fieldset disabled={!owner||busy}><div className="form-grid"><label>Hotel name<input value={form.name} minLength={2} maxLength={120} required onChange={e=>setForm({...form,name:e.target.value})}/></label><label>Timezone<select value={form.timezone} onChange={e=>setForm({...form,timezone:e.target.value})}>{['Europe/London','Europe/Paris','Europe/Berlin','America/New_York','America/Los_Angeles','Asia/Dubai','Asia/Singapore','Australia/Sydney','UTC'].map(t=><option key={t}>{t}</option>)}</select></label></div><label>Email signature<textarea rows={4} maxLength={2000} value={form.signature} onChange={e=>setForm({...form,signature:e.target.value})}/></label><div className="form-actions"><button className="button primary" disabled={busy}>Save hotel settings</button></div></fieldset></form></section><section className="settings-card"><div className="section-heading"><Mail size={21}/><div><h2>Connected mailbox</h2><p>Bring recent guest messages into your shared inbox.</p></div></div>{mailboxes.items.map(m=><div className="mailbox" key={m.id}><span className="google-mark">G</span><div><strong>{m.email}</strong><small>{m.syncError||(m.lastSyncAt?'Last synced '+date(m.lastSyncAt):'Waiting for first synchronization')}</small></div><span className="status Completed">{m.status}</span></div>)}{!mailboxes.items.length&&<p className="muted">No mailbox connected yet.</p>}<button className="button secondary" disabled={busy||!mailboxes.configured||!owner} onClick={()=>run(async()=>{const r=await api<{url:string}>('/integrations/google/connect','POST');location.assign(r.url);})}><span className="google-mark">G</span>{mailboxes.items.length?'Connect or reconnect Google':'Connect Google mailbox'}<ArrowUpRight size={16}/></button>{!mailboxes.configured&&<p className="small muted">{preview?'Real mailbox connections are unavailable in this sample workspace.':'Your administrator needs to configure Google connection before this is available.'}</p>}<div className="settings-note"><ShieldCheck size={17}/><span>Read-only connection. GuestOps does not send, delete or change your Google emails in this first release.</span></div></section><section className="settings-card"><div className="section-heading"><ShieldCheck size={21}/><div><h2>Reply controls</h2><p>Your team makes the final decision.</p></div><span className="status Completed">Draft only</span></div><p>Prepare and save replies here, then send from your hotel mailbox. Automatic sending is not enabled in this migration milestone.</p></section></div>;
|
||||
return <div className="page settings-page"><PageHeading eyebrow="Make yourself at home" title="Hotel settings" text="The details that make this workspace yours."/>{result&&<div className={result==='connected'?'success-note':'alert'} role="status">{result==='connected'?'Google mailbox connected. Recent messages will appear after synchronization.':result==='cancelled'?'Google connection was cancelled.':'Google connection could not be completed. Try again or contact your administrator.'}</div>}<section className="settings-card"><div className="section-heading"><Building2 size={20}/><div><h2>Your hotel</h2><p>Shared with everyone in this workspace.</p></div></div><form onSubmit={e=>{e.preventDefault();run(async()=>onSave(await api<Hotel>('/hotel','PUT',form)));}}><fieldset disabled={!owner||busy}><div className="form-grid"><label>Hotel name<input value={form.name} minLength={2} maxLength={120} required onChange={e=>setForm({...form,name:e.target.value})}/></label><label>Timezone<select value={form.timezone} onChange={e=>setForm({...form,timezone:e.target.value})}>{['Europe/London','Europe/Paris','Europe/Berlin','America/New_York','America/Los_Angeles','Asia/Dubai','Asia/Singapore','Australia/Sydney','UTC'].map(t=><option key={t}>{t}</option>)}</select></label></div><label>Email signature<textarea rows={4} maxLength={2000} value={form.signature} onChange={e=>setForm({...form,signature:e.target.value})}/></label><div className="form-actions"><button className="button primary" disabled={busy}>Save hotel settings</button></div></fieldset></form></section><section className="settings-card"><div className="section-heading"><Mail size={21}/><div><h2>Connected mailbox</h2><p>Bring recent guest messages into your shared inbox.</p></div></div>{mailboxes.items.map(m=><div className="mailbox" key={m.id}><span className="google-mark">G</span><div><strong>{m.email}</strong><small>{m.syncError||(m.lastSyncAt?'Last synced '+date(m.lastSyncAt):'Waiting for first synchronization')}</small></div><span className="status Completed">{m.status}</span></div>)}{!mailboxes.items.length&&<p className="muted">No mailbox connected yet.</p>}<button className="button secondary" disabled={busy||!mailboxes.configured||!owner} onClick={()=>run(async()=>{const r=await api<{url:string}>('/integrations/google/connect','POST');location.assign(r.url);})}><span className="google-mark">G</span>{mailboxes.items.length?'Connect or reconnect Google':'Connect Google mailbox'}<ArrowUpRight size={16}/></button>{!mailboxes.configured&&<p className="small muted">{preview?'Real mailbox connections are unavailable in this sample workspace.':'Your administrator needs to configure Google connection before this is available.'}</p>}<div className="settings-note"><ShieldCheck size={17}/><span>Sending requires Google permission, the hotel sending control and staff approval of each reply. GuestOps does not delete your Google emails.</span></div></section><ReplyControls hotel={hotel} mailboxes={mailboxes} owner={owner} busy={busy} run={run} onSave={onSave}/></div>;
|
||||
}
|
||||
createRoot(document.getElementById('root')!).render(<App/>);
|
||||
|
||||
@@ -7,3 +7,5 @@
|
||||
.message-card h3,.message-top strong{font-size:14px}.message-card p{font-size:14px}.email-body,.reply-box textarea{font-size:16px}.page-heading p,.knowledge-card p{color:#65745f}.message-card p{color:#6c7c62}.message-bottom>span:last-child{color:#738368}.reply-header .small,.below-draft{color:#6d7e61}
|
||||
@media(max-width:1000px){.sidebar-bottom{display:block;margin-top:auto;padding-top:10px}.sidebar-bottom .mode-card,.profile>div,.profile-avatar{display:none}.profile{justify-content:center}.profile .icon-button{margin:0}.preview-pill{display:inline-flex}.topbar-right:has(.preview-pill) .draft-mode{display:none}}
|
||||
@media(prefers-reduced-motion:no-preference){.button,.nav-item,.message-card{transition:background .15s ease}.toast{animation:appear .2s ease}@keyframes appear{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}}
|
||||
|
||||
.reply-actions{padding:18px 0;border-bottom:1px solid var(--line);overflow-wrap:anywhere}.reply-actions details{padding:12px;background:#f3f5ef;border-radius:10px}.reply-actions details p{white-space:pre-wrap}.reply-actions .form-actions{flex-wrap:wrap;gap:8px}.reply-actions p{line-height:1.6}
|
||||
|
||||
Reference in New Issue
Block a user