WIP 2.0.0: AI buttons on the five screens, eval set, privacy notice
Describe your event (new event), Improve/Shorter/Fix mistakes (event description, banner, email and WhatsApp boxes), Draft with AI (email and WhatsApp attendees), Summarise this report (people-free reports) and Summarise feedback (per event). Built-in privacy notice text for AI (2.0.0 entry in BUILT_IN_UPDATES). npm run ai:eval runs the trial cases through the Hub with fact checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMeckMWrKPfc1MMyMJF
This commit is contained in:
@@ -33,6 +33,22 @@ and this project follows [Semantic Versioning](https://semver.org/).
|
||||
phone numbers and ID numbers in what's sent are swapped for placeholders and put back in the
|
||||
answer, so they never leave the site. Two checks are worked out in code as well as by the AI: a
|
||||
weekday that doesn't match its date, and costs a full event can't cover.
|
||||
- **AI buttons in the app** (only where the licence has AI; supervisors and admins):
|
||||
- New event → **Describe your event**: a few sentences fill in the form (details, dates, tickets,
|
||||
early bird; course dates as sessions), with the checks and a budget from the notes to look at
|
||||
first. Nothing changes until "Fill in the form".
|
||||
- **Improve / Shorter / Fix mistakes** under the event description, the site banner, and the
|
||||
email and WhatsApp message boxes; the suggestion replaces the text only with "Use this".
|
||||
- **Draft with AI** in Email attendees and WhatsApp attendees: a short note becomes the email's
|
||||
subject and body, or the WhatsApp message, with `{{name}}` and the event's details.
|
||||
- **Summarise this report** on reports without people in them, and **Summarise feedback** per
|
||||
event on the Feedback summary report.
|
||||
- Every suggestion says "AI suggestion — check it before saving".
|
||||
- **Privacy notice:** the built-in text says how the AI helpers use information and where requests
|
||||
go (sections 4 and 9). Sites with their own published notice see the change in the notice
|
||||
editor.
|
||||
- `npm run ai:eval` (backend): the helpers' eval set — fixed examples run through the site's Hub
|
||||
connection, with automatic checks on the facts and every answer printed to read.
|
||||
|
||||
## [1.51.17] - 2026-10-30 — security release
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
"set-demo": "node scripts/set-demo.js",
|
||||
"build": "tsc -p tsconfig.json && node -e \"require('fs').writeFileSync('dist/build.json', JSON.stringify({ version: require('./package.json').version, builtAt: new Date().toISOString() }))\"",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"openapi": "tsx scripts/openapi.ts"
|
||||
"openapi": "tsx scripts/openapi.ts",
|
||||
"ai:eval": "tsx scripts/ai-eval.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cj-tech-master/excelts": "^10.2.0",
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* The AI helpers' eval set (roadmap §15): `npm run ai:eval` in backend/.
|
||||
*
|
||||
* Runs fixed examples of all five helpers through this site's real Hub connection (so the site must
|
||||
* be connected and its licence must have an AI allowance), checks the facts that matter
|
||||
* automatically, and prints every answer for a person to read. Run it after changing a helper's
|
||||
* instructions or the model on the Hub, and compare with the last run. It costs about R1 a run
|
||||
* with Claude Sonnet 5.5; the calls count against this site's allowance.
|
||||
*
|
||||
* The examples come from the October 2026 model trial; the inputs are made up and hold no
|
||||
* personal information.
|
||||
*/
|
||||
import { prisma } from '../src/v2/legacy';
|
||||
import { draftEvent, summariseReport, draftMessage, summariseFeedback, improveText } from '../src/ai/helpers';
|
||||
|
||||
type Check = [label: string, ok: boolean];
|
||||
type Case = { name: string; run: (userId: string) => Promise<{ output: unknown; checks: Check[] }> };
|
||||
|
||||
const has = (text: unknown, re: RegExp) => re.test(JSON.stringify(text));
|
||||
const near = (n: number, target: number, give = 1) => Math.abs(n - target) <= give;
|
||||
|
||||
const CAMP_NOTES = 'Youth camp for grades 8–12, Fri 14 March 18:00 to Sun 16 March 14:00 at Camp Wartburg near Pietermaritzburg. 60 places. R450 per person, R400 if they book by 31 January. Parents must give consent. Theme "Rooted" (Colossians 2:7). Costs: venue R180 per person per night including meals, bus hire R6 500 return, speaker gift R1 000, T-shirts R95 each. Friday evening worship, Saturday sessions morning and evening with sport in the afternoon, Sunday morning service before we leave. Bring a sleeping bag, Bible and a torch.';
|
||||
|
||||
const FEEDBACK_COMMENTS = [
|
||||
'The keynote on Saturday morning was exactly what I needed this year.', 'Could not hear a thing in Hall B, the sound kept cutting out.',
|
||||
'Lunch queue took 40 minutes, we missed the start of the afternoon session.', 'Loved the worship, so good to be together again.',
|
||||
'Breakouts were too short, just as it got deep we had to leave.', 'Check-in with the QR code was so quick, well done.',
|
||||
'Parking was a nightmare, we parked on the road and walked.', 'Please have childcare next year, I almost could not come.',
|
||||
'Speaker in the parenting breakout was brilliant.', 'Sound in Hall B again, the mic was crackling the whole time.',
|
||||
'Food ran out of vegetarian options by the time we got there.', 'The whole day felt so well organised.',
|
||||
'More time for breakouts please, and maybe fewer of them.', 'Lunch took forever.', 'Loved the gift bags!',
|
||||
'Hall A was freezing, the aircon was too cold.', 'The app reminders the day before were really helpful.',
|
||||
'Would love a longer Q&A with the main speaker.', 'Queue for lunch was very long, maybe stagger the breakouts?',
|
||||
'Parking marshals would help a lot.', 'Worship team was amazing.', 'Childcare or a kids programme would let young moms come.',
|
||||
'Some of the slides were hard to read from the back.', 'Best conference yet, thank you to the whole team.',
|
||||
'I would pay a bit more for a better lunch.', 'Hall B sound please fix it.',
|
||||
];
|
||||
|
||||
const CASES: Case[] = [
|
||||
{
|
||||
name: 'Draft an event — full notes with costs',
|
||||
async run(userId) {
|
||||
const r = await draftEvent(userId, CAMP_NOTES);
|
||||
const d = r.draft;
|
||||
return {
|
||||
output: r,
|
||||
checks: [
|
||||
['price R450, early bird R400 until 31 January', d.ticketOptions[0]?.priceRand === 450 && d.ticketOptions[0]?.earlyBirdPriceRand === 400 && d.ticketOptions[0]?.earlyBirdUntil.endsWith('-01-31')],
|
||||
['60 places, parental consent', d.capacity === 60 && d.needsParentalConsent],
|
||||
['budget R34 800, break-even 78', r.totalCostRand === 34800 && r.breakEvenPlaces === 78],
|
||||
['warns the camp is short even when full', r.warnings.some(w => w.includes('short'))],
|
||||
['times not in the notes left empty (only 18:00 and 14:00 given)', d.sessions.every(s => !s.startTime || s.startTime === '18:00')],
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Summarise a report — a month of payments',
|
||||
async run(userId) {
|
||||
const { summary } = await summariseReport(userId, {
|
||||
reportKey: 'revenue', title: 'Revenue summary — October 2026 (September for comparison)',
|
||||
columns: ['Method', 'October payments', 'October amount', 'September payments', 'September amount'],
|
||||
rows: [['Card', 96, 'R42 300', 81, 'R35 100'], ['EFT', 14, 'R18 000', 17, 'R21 500'], ['Cash at the door', 31, 'R6 250', 22, 'R4 100'], ['Refunds', 4, 'R2 700', 2, 'R450']],
|
||||
stats: [{ label: 'Card payments waiting for the provider over 2 days', value: '3 (R1 350)' }],
|
||||
});
|
||||
return {
|
||||
output: summary,
|
||||
checks: [
|
||||
['October total R66 550', has(summary, /66[\s ]?550/)],
|
||||
['up on September (R60 700)', has(summary, /60[\s ]?700|5[\s ]?850|9[.,]6/)],
|
||||
['the 3 waiting card payments need checking', has(summary.watchOut, /1[\s ]?350|3 (online |card )?payments/i)],
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Summarise feedback — women\'s conference',
|
||||
async run(userId) {
|
||||
const { summary } = await summariseFeedback(userId, {
|
||||
event: { title: 'Women\'s Conference 2026' }, responses: 112, invited: 186,
|
||||
questions: [
|
||||
{ label: 'Overall', type: 'rating', answered: 112, average: 4.4 }, { label: 'Venue', type: 'rating', answered: 110, average: 3.9 },
|
||||
{ label: 'Food', type: 'rating', answered: 108, average: 3.6 }, { label: 'Comments', type: 'text', answered: FEEDBACK_COMMENTS.length, texts: FEEDBACK_COMMENTS },
|
||||
],
|
||||
});
|
||||
const count = (re: RegExp) => summary.improve.find(t => re.test(t.theme))?.mentions ?? -1;
|
||||
return {
|
||||
output: summary,
|
||||
checks: [
|
||||
['lunch/food raised by about 5', near(count(/lunch|food|queue/i), 5)],
|
||||
['Hall B sound raised by 3', near(count(/sound|hall b/i), 3, 0)],
|
||||
['quotes copied exactly', summary.quotes.every(q => FEEDBACK_COMMENTS.includes(q))],
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Draft a message — WhatsApp reminder',
|
||||
async run(userId) {
|
||||
const { message } = await draftMessage(userId, { channel: 'whatsapp', note: 'Youth camp this weekend: remind them to bring a sleeping bag; the bus leaves at 7:30 on Friday from the church car park.' });
|
||||
return {
|
||||
output: message,
|
||||
checks: [
|
||||
['uses {{name}}', message.body.includes('{{name}}')],
|
||||
['keeps 7:30, sleeping bag, car park', /7:30/.test(message.body) && /sleeping bag/i.test(message.body) && /car park/i.test(message.body)],
|
||||
['no "reminda" (seen with Haiku)', !/reminda/i.test(message.body)],
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Draft a message — email about a venue change',
|
||||
async run(userId) {
|
||||
const { message } = await draftMessage(userId, { channel: 'email', note: 'Men\'s breakfast this Saturday is moving from the church hall to the Protea Hotel on Main Road because the hall is being renovated. Same time, 7:00. Park at the back of the hotel. Price stays R120, nothing to do if you\'ve paid. Speaker is still Pastor Mike. Questions: events@church.example.org' });
|
||||
return {
|
||||
output: message,
|
||||
checks: [
|
||||
['has a subject', message.subject.trim().length > 5],
|
||||
['keeps the facts', /Protea/.test(message.body) && /7:00/.test(message.body) && /R120/.test(message.body)],
|
||||
['the email address came back intact', message.body.includes('events@church.example.org')],
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Improve this text — a messy description',
|
||||
async run(userId) {
|
||||
const { result } = await improveText(userId, { text: 'join us for are anual family fun day!!! theres jumping castles, food stalls and a talent show for the kids. Bring the hole family its going to be awesome. tickets R50 for adults kids under 12 free. starts 9 till 2 on the church field, if it rains we move inside to the hall. please register so we know how many boerewors rolls to make lol', mode: 'improve', where: 'description' });
|
||||
return {
|
||||
output: result,
|
||||
checks: [
|
||||
['spelling fixed', /annual/i.test(result.text) && /whole family/i.test(result.text) && !/\bare anual\b/.test(result.text)],
|
||||
['every fact kept (R50, under 12, 9 to 2, hall)', /R50/.test(result.text) && /12/.test(result.text) && /\b9\b/.test(result.text) && /\b2\b/.test(result.text) && /hall/i.test(result.text)],
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
(async () => {
|
||||
const admin = await prisma.user.findFirst({ where: { role: 'admin', isActive: true }, select: { id: true } });
|
||||
if (!admin) throw new Error('No active admin to log the calls against.');
|
||||
let passed = 0;
|
||||
let total = 0;
|
||||
for (const c of CASES) {
|
||||
console.log(`\n━━ ${c.name}`);
|
||||
try {
|
||||
const { output, checks } = await c.run(admin.id);
|
||||
for (const [label, ok] of checks) {
|
||||
total++;
|
||||
if (ok) passed++;
|
||||
console.log(` ${ok ? '✓' : '✗'} ${label}`);
|
||||
}
|
||||
console.log(JSON.stringify(output, null, 2).split('\n').map(l => ` ${l}`).join('\n'));
|
||||
} catch (e) {
|
||||
total++;
|
||||
console.log(` ✗ failed: ${(e as Error).message}`);
|
||||
}
|
||||
}
|
||||
console.log(`\n${passed} of ${total} checks passed. Read the answers too: the checks only cover the facts.`);
|
||||
await prisma.$disconnect();
|
||||
process.exit(passed === total ? 0 : 1);
|
||||
})().catch(async e => {
|
||||
console.error(e);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -96,6 +96,7 @@ const DEFAULT_SECTIONS = [
|
||||
'• Tell you when a new event in a series you follow comes out. This counts as news, so it\'s only sent if you get news and announcements.',
|
||||
'• Offer places from a waitlist, arrange rooms and groups, and ask for parental consent on youth events.',
|
||||
'• Send you an optional feedback form after an event, with one reminder.',
|
||||
'• If we use the AI helpers: our staff can ask an AI service to help draft event details and messages, improve text, and summarise reports and event feedback. A person checks every suggestion before anything is saved or sent. Only what a task needs is sent — never your name, contact details, or medical or children\'s information — and feedback comments are sent without who wrote them (see section 9).',
|
||||
'• Manage user accounts and event attendance records, and give support when you ask for help.',
|
||||
'• Improve our events and website (using anonymous statistics, and only with your permission).',
|
||||
'• Comply with legal obligations.',
|
||||
@@ -166,6 +167,7 @@ const DEFAULT_SECTIONS = [
|
||||
'We do not sell or rent your personal information. Outside our organisation, it is shared only with these service providers ("operators"), each only for its purpose:',
|
||||
'{operators}',
|
||||
'• Anyone we are required to share it with under South African law.',
|
||||
'If we use the AI helpers, requests go through our software provider\'s service to Anthropic (the Claude AI service) in the United States, which is listed above. Our software provider does not keep what was sent. Anthropic handles it under its commercial terms, which do not allow it to be used to train AI; it may be kept for a short time for safety checks. Because this is outside South Africa, it is only done under the protections POPIA requires for such transfers.',
|
||||
'If we connect another system — for example our church-management software — through a webhook, it is listed above with what it receives. It gets only the updates we chose (such as new registrations, payments and check-ins), and never children\'s details from kids check-in.',
|
||||
'Within our organisation, people see only what they need:',
|
||||
"• Door staff see a ticket's holder name, ticket type and check-in status when scanning.",
|
||||
@@ -279,6 +281,14 @@ const BUILT_IN_UPDATES = [
|
||||
],
|
||||
sections: ['summary', 'information', 'use', 'whatsapp', 'retention', 'sharing', 'cookies', 'changes'],
|
||||
},
|
||||
{
|
||||
revision: '2.0.0',
|
||||
summary: [
|
||||
'AI helpers: staff can ask an AI service (Anthropic\'s Claude, through the software provider) to draft events and messages, improve text and summarise reports and feedback; a person checks every suggestion, and no names, contact details, medical or children\'s information are sent.',
|
||||
'Where AI requests go (the United States), that the provider doesn\'t keep them, and that they aren\'t used to train AI.',
|
||||
],
|
||||
sections: ['use', 'sharing'],
|
||||
},
|
||||
];
|
||||
const BUILT_IN_REVISION = BUILT_IN_UPDATES[BUILT_IN_UPDATES.length - 1].revision;
|
||||
const REVIEWED_KEY = 'privacy_notice_builtin_reviewed';
|
||||
|
||||
@@ -14,6 +14,8 @@ import { MessageKindPicker, matchedText, type MessageKind } from "@/components/s
|
||||
import { CampusAudiencePicker } from "@/components/shared/CampusAudiencePicker";
|
||||
import { EventPicker } from "@/components/shared/EventPicker";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
import { AiDraftMessage } from "@/components/shared/AiDraftMessage";
|
||||
import { AiImprove } from "@/components/shared/AiImprove";
|
||||
|
||||
type Attendee = { id: string; name: string; email: string; pref: string };
|
||||
type TemplateKey = 'custom'|'payment_reminder'|'event_reminder'|'tickets';
|
||||
@@ -614,9 +616,13 @@ function EmailAttendeesPageInner() {
|
||||
|
||||
{templateKey !== 'tickets' ? (
|
||||
<div>
|
||||
<div className="mb-2">
|
||||
<AiDraftMessage channel="email" eventId={eventId || undefined} onUse={d => { setSubject(d.subject); setSubjectDirty(true); setBody(d.body); setBodyDirty(true); }} />
|
||||
</div>
|
||||
<label className="block text-xs text-gray-600 mb-1">Message</label>
|
||||
<textarea className="w-full border rounded px-3 py-2 text-sm" rows={8} value={body} onChange={e => { setBody(e.target.value); setBodyDirty(true); }} placeholder="Write your message to attendees..." />
|
||||
<div className="text-[11px] text-gray-500 mt-1">Hint: Start with <html> or <div> to send HTML; otherwise plain text will be sent.</div>
|
||||
{!/^\s*</.test(body) && <AiImprove text={body} onChange={t => { setBody(t); setBodyDirty(true); }} where="message" />}
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-3 border rounded bg-gray-50 text-sm text-gray-700">This will send each selected attendee their ticket(s) as attachments for this event.</div>
|
||||
|
||||
@@ -22,6 +22,8 @@ import {
|
||||
} from "@/components/events/ScheduleEditor";
|
||||
import { toSessionDraft, scheduleSummary } from "@/lib/sessions";
|
||||
import { fetchApiFile, openBlob } from "@/lib/export";
|
||||
import { AiEventDraft, type AiEventDraftFields } from "@/components/events/AiEventDraft";
|
||||
import { AiImprove } from "@/components/shared/AiImprove";
|
||||
import { apiV2, apiV2Data } from "@/lib/apiV2";
|
||||
import { createTicketOption, updateTicketOption, listSections, createSection, updateSection, deleteSection, listAttachments, uploadAttachment, deleteAttachment, uploadImage } from "@/lib/eventSetup";
|
||||
|
||||
@@ -1127,6 +1129,33 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
|
||||
const upd = (patch: Partial<EventDraft>) => setDraft(d => ({ ...d, ...patch }));
|
||||
|
||||
// ── AI: "Describe your event" fills in the form (a person checks every step before saving) ──
|
||||
const applyAiDraft = (a: AiEventDraftFields) => {
|
||||
const at = (date: string, time: string, fallback: string) => (date ? `${date}T${time || fallback}` : "");
|
||||
const asSessions = a.sessions.length > 1;
|
||||
upd({
|
||||
...(a.title ? { title: a.title } : {}),
|
||||
...(a.description ? { description: a.description } : {}),
|
||||
...(a.location ? { location: a.location } : {}),
|
||||
requiresParentalConsent: a.needsParentalConsent,
|
||||
scheduleType: asSessions ? "sessions" : "single",
|
||||
...(asSessions ? {} : { startDate: at(a.startDate, a.startTime, "09:00"), endDate: at(a.endDate || a.startDate, a.endTime, "17:00") }),
|
||||
...(a.ticketOptions[0] ? { price: String(a.ticketOptions[0].priceRand) } : {}),
|
||||
});
|
||||
if (asSessions) {
|
||||
setSessions(a.sessions.map(s => keyed({ label: s.label, startsAt: at(s.date, s.startTime, "09:00"), endsAt: at(s.date, s.endTime || s.startTime, "17:00"), location: "", cancelled: false, capacity: "" })));
|
||||
}
|
||||
if (a.ticketOptions.length) {
|
||||
setOptions(a.ticketOptions.map((t, i) => ({
|
||||
name: t.name || "Ticket", price: String(t.priceRand), isMainTicket: i === 0,
|
||||
// The event's places go on the main ticket; 0 means no limit.
|
||||
stockLimit: i === 0 && a.capacity > 0 ? String(a.capacity) : "0",
|
||||
earlyBirdTiers: t.earlyBirdPriceRand > 0 && t.earlyBirdUntil ? [{ deadline: `${t.earlyBirdUntil}T23:59`, price: String(t.earlyBirdPriceRand), stockLimit: "0" }] : [],
|
||||
variants: [],
|
||||
})));
|
||||
}
|
||||
};
|
||||
|
||||
// ── copy: move every date by the same amount (sessions, deadline, early birds, feedback) ──
|
||||
const copyStart = multi ? scheduleBounds?.start || "" : draft.startDate;
|
||||
const moveAllDates = (newStart: string) => {
|
||||
@@ -1539,6 +1568,7 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
{copyStart && new Date(copyStart) < new Date() && <p className="text-xs text-amber-700">This copy still starts in the past.</p>}
|
||||
</div>
|
||||
)}
|
||||
{mode === "create" && !cloning && <AiEventDraft onApply={applyAiDraft} />}
|
||||
<div>
|
||||
<label className="block text-xs text-gray-600 mb-1">Title <span className="text-red-500">*</span></label>
|
||||
<input className="w-full border rounded px-3 py-2 text-sm" value={draft.title} onChange={e => upd({ title: e.target.value })} placeholder="Event title" />
|
||||
@@ -1546,6 +1576,7 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
<div>
|
||||
<label className="block text-xs text-gray-600 mb-1">Description</label>
|
||||
<textarea className="w-full border rounded px-3 py-2 text-sm" rows={3} value={draft.description} onChange={e => upd({ description: e.target.value })} />
|
||||
<AiImprove text={draft.description} onChange={description => upd({ description })} where="description" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="block text-xs text-gray-600 mb-1">When <span className="text-red-500">*</span></div>
|
||||
|
||||
@@ -14,6 +14,8 @@ import { MessageKindPicker, matchedText, type MessageKind } from "@/components/s
|
||||
import { CampusAudiencePicker } from "@/components/shared/CampusAudiencePicker";
|
||||
import { EventPicker } from "@/components/shared/EventPicker";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
import { AiDraftMessage } from "@/components/shared/AiDraftMessage";
|
||||
import { AiImprove } from "@/components/shared/AiImprove";
|
||||
|
||||
// Attendee with preference info
|
||||
type Attendee = { id: string; name: string; phone: string; pref: string };
|
||||
@@ -716,10 +718,14 @@ function WhatsAppAttendeesPageInner() {
|
||||
|
||||
{templateKey !== "tickets" ? (
|
||||
<div>
|
||||
<div className="mb-2">
|
||||
<AiDraftMessage channel="whatsapp" eventId={eventId || undefined} onUse={d => { setMessage(d.body); messageDirtyRef.current = true; }} />
|
||||
</div>
|
||||
<label className="block text-xs text-gray-600 mb-1">Message</label>
|
||||
<textarea className="w-full border rounded px-3 py-2 text-sm" rows={8} value={message}
|
||||
onChange={(e) => { setMessage(e.target.value); messageDirtyRef.current = true; }}
|
||||
placeholder="Write your WhatsApp message to attendees..." />
|
||||
<AiImprove text={message} onChange={t => { setMessage(t); messageDirtyRef.current = true; }} where="message" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-3 border rounded bg-gray-50 text-sm text-gray-700">
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useRouter } from "next/navigation";
|
||||
import { Megaphone } from "lucide-react";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
import { AiImprove } from "@/components/shared/AiImprove";
|
||||
|
||||
type BannerType = "info" | "warning" | "success" | "danger";
|
||||
|
||||
@@ -124,6 +125,7 @@ export default function SetBannerPage() {
|
||||
value={message}
|
||||
onChange={e => setMessage(e.target.value)}
|
||||
/>
|
||||
<AiImprove text={message} onChange={setMessage} where="banner" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
"use client";
|
||||
|
||||
import React, { useId, useState } from "react";
|
||||
import { AlertTriangle, Sparkles } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useAiStatus } from "@/hooks/useAiStatus";
|
||||
import { runAi } from "@/lib/ai";
|
||||
import type { V2Result } from "@/lib/apiV2";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { AiButton, AiNotice } from "@/components/shared/AiButton";
|
||||
|
||||
export type AiEventDraftResult = V2Result<"/ai/draft-event", "post">["data"]["output"];
|
||||
export type AiEventDraftFields = AiEventDraftResult["draft"];
|
||||
|
||||
const money = (n: number) => `R${Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ")}`;
|
||||
|
||||
/**
|
||||
* "Describe your event": a few sentences in, the event form filled in (after a person checks the
|
||||
* suggestion). Hidden on sites without AI. The budget from the notes is shown, not saved — costs
|
||||
* are entered on the event by admins.
|
||||
*/
|
||||
export function AiEventDraft({ onApply }: { onApply: (draft: AiEventDraftFields) => void }) {
|
||||
const { token } = useAuth();
|
||||
const status = useAiStatus();
|
||||
const notesId = useId();
|
||||
const [notes, setNotes] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [result, setResult] = useState<AiEventDraftResult | null>(null);
|
||||
if (!status?.enabled) return null;
|
||||
|
||||
const run = async () => {
|
||||
if (!token || notes.trim().length < 10) { setError("Describe the event in a sentence or two first."); return; }
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
setResult(await runAi<AiEventDraftResult>("draft_event", { notes }, token));
|
||||
} catch (e) { setError(errorMessage(e) || "The AI couldn't draft this event."); }
|
||||
setBusy(false);
|
||||
};
|
||||
|
||||
const d = result?.draft;
|
||||
const checks = result ? [...result.warnings, ...d!.checks] : [];
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-violet-200 bg-violet-50/60 p-3" data-testid="ai-event-draft">
|
||||
<label htmlFor={notesId} className="flex items-center gap-1.5 text-sm font-medium text-violet-900">
|
||||
<Sparkles className="h-4 w-4" aria-hidden /> Describe your event
|
||||
</label>
|
||||
<textarea
|
||||
id={notesId} rows={3} maxLength={4000}
|
||||
className="w-full rounded border bg-white px-3 py-2 text-sm"
|
||||
placeholder="e.g. Youth camp for grades 8–12, Fri 13 March 18:00 to Sun 15 March 14:00 at Camp Wartburg. 60 places, R450 or R400 if they book by 31 January. Parents must give consent. Costs: venue R180 per person per night, bus R6 500."
|
||||
value={notes} onChange={e => setNotes(e.target.value)}
|
||||
/>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<AiButton helper="draft_event" onClick={run} busy={busy} size="sm">{busy ? "Drafting…" : "Draft the event"}</AiButton>
|
||||
<span className="text-xs text-gray-500">Fills in the details, tickets and dates for you to check.</span>
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-700" role="alert">{error}</p>}
|
||||
|
||||
{d && (
|
||||
<div className="space-y-3 rounded border border-violet-200 bg-white p-3 text-sm">
|
||||
<AiNotice />
|
||||
<div>
|
||||
<p className="font-medium">{d.title}</p>
|
||||
<p className="text-gray-600">
|
||||
{[d.startDate && `${d.startDate}${d.startTime ? ` ${d.startTime}` : ""}`, d.endDate && `to ${d.endDate}${d.endTime ? ` ${d.endTime}` : ""}`].filter(Boolean).join(" ")}
|
||||
{d.location ? ` · ${d.location}` : ""}{d.capacity ? ` · ${d.capacity} places` : ""}{d.needsParentalConsent ? " · parental consent" : ""}
|
||||
</p>
|
||||
{d.ticketOptions.length > 0 && (
|
||||
<p className="text-gray-600">
|
||||
{d.ticketOptions.map(t => `${t.name} ${money(t.priceRand)}${t.earlyBirdPriceRand > 0 ? ` (${money(t.earlyBirdPriceRand)} until ${t.earlyBirdUntil || "?"})` : ""}`).join(" · ")}
|
||||
</p>
|
||||
)}
|
||||
{d.sessions.length > 1 && <p className="text-gray-600">{d.sessions.length} sessions</p>}
|
||||
</div>
|
||||
|
||||
{checks.length > 0 && (
|
||||
<ul className="space-y-1 rounded border border-amber-200 bg-amber-50 p-2 text-amber-900" aria-label="Check before saving">
|
||||
{checks.map(c => <li key={c} className="flex gap-1.5"><AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" aria-hidden />{c}</li>)}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{d.costs.length > 0 && (
|
||||
<div>
|
||||
<p className="text-xs font-medium uppercase tracking-wide text-gray-500">Budget from your notes (not saved)</p>
|
||||
<table className="mt-1 w-full text-xs tabular-nums">
|
||||
<tbody>
|
||||
{d.costs.map(c => <tr key={c.item} className="border-t"><td className="py-1 pr-2">{c.item}<span className="block text-gray-500">{c.basis}</span></td><td className="py-1 text-right">{money(c.amountRand)}</td></tr>)}
|
||||
<tr className="border-t font-medium"><td className="py-1">Total</td><td className="py-1 text-right">{money(result!.totalCostRand)}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{result!.breakEvenPlaces != null && <p className="mt-1 text-xs text-gray-600">Break-even: {result!.breakEvenPlaces} places at the full price.</p>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button type="button" className="rounded bg-brand-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-brand-700" onClick={() => { onApply(d); setResult(null); }}>
|
||||
Fill in the form
|
||||
</button>
|
||||
<button type="button" className="rounded border px-3 py-1.5 text-sm hover:bg-gray-50" onClick={() => setResult(null)}>Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useAiStatus } from "@/hooks/useAiStatus";
|
||||
import { runAi } from "@/lib/ai";
|
||||
import type { V2Result } from "@/lib/apiV2";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { AiButton, AiNotice } from "@/components/shared/AiButton";
|
||||
|
||||
type Summary = V2Result<"/ai/summarise-feedback", "post">["data"]["output"];
|
||||
|
||||
const Themes = ({ title, list }: { title: string; list: { theme: string; mentions: number }[] }) => (
|
||||
<div>
|
||||
<p className="text-xs font-medium uppercase tracking-wide text-gray-500">{title}</p>
|
||||
{list.length === 0 ? <p className="text-gray-500">—</p> : (
|
||||
<ul className="mt-1 space-y-0.5">
|
||||
{list.map(t => <li key={t.theme} className="flex justify-between gap-3"><span>{t.theme}</span><span className="shrink-0 tabular-nums text-gray-500">{t.mentions}</span></li>)}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* "Summarise feedback" for one event: how it went, what people liked and want improved (with how
|
||||
* many said so), a few quotes and suggestions. The server sends the answers without who gave them
|
||||
* and records it in the access log. Hidden on sites without AI.
|
||||
*/
|
||||
export function AiFeedbackSummary({ eventId, responses }: { eventId: string; responses: number }) {
|
||||
const { token } = useAuth();
|
||||
const status = useAiStatus();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [summary, setSummary] = useState<Summary | null>(null);
|
||||
if (!status?.enabled || responses < 1) return null;
|
||||
|
||||
const run = async () => {
|
||||
if (!token) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try { setSummary(await runAi<Summary>("summarise_feedback", { eventId }, token)); } catch (e) { setError(errorMessage(e) || "The AI couldn't summarise this feedback."); }
|
||||
setBusy(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mb-3 space-y-2">
|
||||
{!summary && <AiButton helper="summarise_feedback" size="sm" busy={busy} onClick={run}>{busy ? "Summarising…" : "Summarise feedback"}</AiButton>}
|
||||
{error && <p className="text-sm text-red-700" role="alert">{error}</p>}
|
||||
{summary && (
|
||||
<div className="space-y-3 rounded-lg border border-violet-200 bg-violet-50/60 p-3 text-sm">
|
||||
<AiNotice />
|
||||
<p>{summary.overall}</p>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Themes title="Liked" list={summary.liked} />
|
||||
<Themes title="To improve" list={summary.improve} />
|
||||
</div>
|
||||
{summary.quotes.length > 0 && (
|
||||
<div className="space-y-1">{summary.quotes.map(q => <blockquote key={q} className="border-l-2 border-violet-300 pl-2 italic text-gray-700">{q}</blockquote>)}</div>
|
||||
)}
|
||||
{summary.nextTime.length > 0 && (
|
||||
<div>
|
||||
<p className="text-xs font-medium uppercase tracking-wide text-gray-500">Next time</p>
|
||||
<ul className="ml-4 mt-1 list-disc space-y-0.5">{summary.nextTime.map(n => <li key={n}>{n}</li>)}</ul>
|
||||
</div>
|
||||
)}
|
||||
<button type="button" className="text-xs text-gray-600 underline" onClick={() => setSummary(null)}>Hide the summary</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { AlertTriangle } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useAiStatus } from "@/hooks/useAiStatus";
|
||||
import { runAi } from "@/lib/ai";
|
||||
import type { V2Body, V2Result } from "@/lib/apiV2";
|
||||
import type { ReportPdfPayload } from "@/lib/export";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { AiButton, AiNotice } from "@/components/shared/AiButton";
|
||||
|
||||
type Summary = V2Result<"/ai/summarise-report", "post">["data"]["output"];
|
||||
type ReportKey = V2Body<"/ai/summarise-report", "post">["reportKey"];
|
||||
|
||||
/** Reports without people in them: only these are sent to the AI (the server checks too). */
|
||||
export const SUMMARISABLE_REPORTS: readonly string[] = ["seriesComparison", "regTypes", "usage", "revenue", "regStatus", "donations", "funnel", "discounts", "cashup", "financeReport", "profitReport"] satisfies ReportKey[];
|
||||
|
||||
/**
|
||||
* "Summarise this report": a headline, a few insights and anything to act on, from the report as
|
||||
* it is on screen (the same data as Print and Excel). Only on reports without people in them;
|
||||
* hidden on sites without AI.
|
||||
*/
|
||||
export function AiReportSummary({ reportKey, getPayload }: { reportKey: string; getPayload: () => ReportPdfPayload | null }) {
|
||||
const { token } = useAuth();
|
||||
const status = useAiStatus();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [summary, setSummary] = useState<Summary | null>(null);
|
||||
if (!status?.enabled || !SUMMARISABLE_REPORTS.includes(reportKey)) return null;
|
||||
|
||||
const run = async () => {
|
||||
const p = getPayload();
|
||||
if (!token || !p?.table) { setError("This report has no figures to summarise yet."); return; }
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
setSummary(await runAi<Summary>("summarise_report", {
|
||||
reportKey, title: p.title, subtitle: p.subtitle,
|
||||
stats: (p.stats || []).map(s => ({ label: s.label, value: s.value })),
|
||||
columns: p.table.columns, rows: p.table.rows,
|
||||
}, token));
|
||||
} catch (e) { setError(errorMessage(e) || "The AI couldn't summarise this report."); }
|
||||
setBusy(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mb-4 space-y-2" data-testid="ai-report-summary">
|
||||
{!summary && <AiButton helper="summarise_report" busy={busy} onClick={run}>{busy ? "Summarising…" : "Summarise this report"}</AiButton>}
|
||||
{error && <p className="text-sm text-red-700" role="alert">{error}</p>}
|
||||
{summary && (
|
||||
<div className="space-y-2 rounded-lg border border-violet-200 bg-violet-50/60 p-4 text-sm">
|
||||
<AiNotice />
|
||||
<p className="font-medium text-gray-900">{summary.headline}</p>
|
||||
<ul className="space-y-1.5">
|
||||
{summary.insights.map(i => <li key={i.title}><span className="font-medium">{i.title}.</span> {i.detail}</li>)}
|
||||
</ul>
|
||||
{summary.watchOut.length > 0 && (
|
||||
<ul className="space-y-1 rounded border border-amber-200 bg-amber-50 p-2 text-amber-900" aria-label="Needs attention">
|
||||
{summary.watchOut.map(w => <li key={w} className="flex gap-1.5"><AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" aria-hidden />{w}</li>)}
|
||||
</ul>
|
||||
)}
|
||||
<button type="button" className="text-xs text-gray-600 underline" onClick={() => setSummary(null)}>Hide the summary</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import { Printer, Mail, FileSpreadsheet, MessageCircle, ShoppingCart, CreditCard
|
||||
import { REPORTS, type ReportKey } from "./ReportCatalog";
|
||||
import ReportsShell from "./ReportsShell";
|
||||
import ReportViewerModal, { ReportActionButton } from "./ReportViewerModal";
|
||||
import { AiReportSummary } from "./AiReportSummary";
|
||||
import { AiFeedbackSummary } from "./AiFeedbackSummary";
|
||||
import { StatTile, StatTileRow } from "./StatTile";
|
||||
import { HorizontalBarChart } from "./charts/HorizontalBarChart";
|
||||
import { AreaTrendChart } from "@/components/charts/AreaTrendChart";
|
||||
@@ -1566,6 +1568,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
|
||||
{!ready && <div className="text-sm text-gray-400">Loading…</div>}
|
||||
{ready && (
|
||||
<>
|
||||
<AiReportSummary key={report} reportKey={report} getPayload={buildReportPayload} />
|
||||
{report === "payments" && (
|
||||
<div>
|
||||
{paymentRows.length === 0 ? (
|
||||
@@ -2015,6 +2018,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
|
||||
{f.sentAt ? `${f.responses} of ${f.invited} responded${f.responseRate != null ? ` (${f.responseRate}%)` : ""}` : "Not sent yet"}{f.anonymous ? " · anonymous" : ""}
|
||||
</div>
|
||||
</div>
|
||||
<AiFeedbackSummary eventId={f.eventId} responses={f.responses || 0} />
|
||||
<div className="space-y-4">
|
||||
{(f.questions || []).map((q) => (
|
||||
<div key={q.fieldId}>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"use client";
|
||||
|
||||
import React, { useId, useState } from "react";
|
||||
import { Sparkles } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useAiStatus } from "@/hooks/useAiStatus";
|
||||
import { runAi } from "@/lib/ai";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { AiButton, AiNotice } from "@/components/shared/AiButton";
|
||||
|
||||
type Draft = { subject: string; body: string };
|
||||
|
||||
/**
|
||||
* "Draft a message": a short note in, an email (subject and body) or WhatsApp message out, using
|
||||
* {{name}} and the event placeholders. The draft goes into the message box only with "Use this",
|
||||
* where it can be edited before sending. Hidden on sites without AI.
|
||||
*/
|
||||
export function AiDraftMessage({ channel, eventId, onUse }: { channel: "email" | "whatsapp"; eventId?: string; onUse: (draft: Draft) => void }) {
|
||||
const { token } = useAuth();
|
||||
const status = useAiStatus();
|
||||
const noteId = useId();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [note, setNote] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [draft, setDraft] = useState<Draft | null>(null);
|
||||
if (!status?.enabled) return null;
|
||||
|
||||
if (!open) {
|
||||
return <AiButton helper="draft_message" size="sm" onClick={() => setOpen(true)}>Draft with AI</AiButton>;
|
||||
}
|
||||
|
||||
const run = async () => {
|
||||
if (!token) return;
|
||||
if (note.trim().length < 3) { setError("Say in a few words what the message is about."); return; }
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try { setDraft(await runAi<Draft>("draft_message", { channel, note, ...(eventId ? { eventId } : {}) }, token)); } catch (e) { setError(errorMessage(e) || "The AI couldn't draft this message."); }
|
||||
setBusy(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-violet-200 bg-violet-50/60 p-3" data-testid="ai-draft-message">
|
||||
<label htmlFor={noteId} className="flex items-center gap-1.5 text-sm font-medium text-violet-900"><Sparkles className="h-4 w-4" aria-hidden /> What should the message say?</label>
|
||||
<textarea id={noteId} rows={2} maxLength={3000} className="w-full rounded border bg-white px-3 py-2 text-sm" value={note} onChange={e => setNote(e.target.value)}
|
||||
placeholder={channel === "whatsapp" ? "e.g. remind them to bring a sleeping bag; the bus leaves at 7:30 on Friday from the church car park" : "e.g. the breakfast moves to the Protea Hotel on Main Road, same time, park at the back, nothing to do if you've paid"} />
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<AiButton helper="draft_message" size="sm" busy={busy} onClick={run}>{busy ? "Drafting…" : `Draft the ${channel === "whatsapp" ? "WhatsApp message" : "email"}`}</AiButton>
|
||||
<button type="button" className="text-xs text-gray-600 underline" onClick={() => { setOpen(false); setDraft(null); setError(null); }}>Close</button>
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-700" role="alert">{error}</p>}
|
||||
{draft && (
|
||||
<div className="space-y-2 rounded border border-violet-200 bg-white p-2 text-sm">
|
||||
<AiNotice />
|
||||
{draft.subject && <p><span className="text-xs text-gray-500">Subject: </span>{draft.subject}</p>}
|
||||
<p className="whitespace-pre-wrap">{draft.body}</p>
|
||||
<div className="flex gap-2">
|
||||
<button type="button" className="rounded bg-brand-600 px-3 py-1 text-xs font-medium text-white hover:bg-brand-700" onClick={() => { onUse(draft); setDraft(null); setOpen(false); }}>Use this</button>
|
||||
<button type="button" className="rounded border px-3 py-1 text-xs hover:bg-gray-50" onClick={() => setDraft(null)}>Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useAiStatus } from "@/hooks/useAiStatus";
|
||||
import { runAi } from "@/lib/ai";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { AiButton, AiNotice } from "@/components/shared/AiButton";
|
||||
|
||||
type Mode = "improve" | "shorter" | "fix";
|
||||
type Answer = { text: string; changes: string[] };
|
||||
const MODES: { mode: Mode; label: string }[] = [
|
||||
{ mode: "improve", label: "Improve" },
|
||||
{ mode: "shorter", label: "Shorter" },
|
||||
{ mode: "fix", label: "Fix mistakes" },
|
||||
];
|
||||
|
||||
/**
|
||||
* "Improve this text" under a text box: improve it, make it shorter, or only fix mistakes. The
|
||||
* suggestion shows beside what was there, and replaces it only with "Use this". Hidden on sites
|
||||
* without AI.
|
||||
*/
|
||||
export function AiImprove({ text, onChange, where }: { text: string; onChange: (text: string) => void; where: "description" | "banner" | "message" }) {
|
||||
const { token } = useAuth();
|
||||
const status = useAiStatus();
|
||||
const [busy, setBusy] = useState<Mode | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [answer, setAnswer] = useState<Answer | null>(null);
|
||||
if (!status?.enabled) return null;
|
||||
|
||||
const run = async (mode: Mode) => {
|
||||
if (!token) return;
|
||||
if (text.trim().length < 3) { setError("Write something first."); return; }
|
||||
setBusy(mode);
|
||||
setError(null);
|
||||
try { setAnswer(await runAi<Answer>("improve_text", { text, mode, where }, token)); } catch (e) { setError(errorMessage(e) || "The AI couldn't improve this text."); }
|
||||
setBusy(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mt-1 space-y-2">
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{MODES.map(m => (
|
||||
<AiButton key={m.mode} helper="improve_text" size="sm" busy={busy === m.mode} onClick={() => run(m.mode)}>{m.label}</AiButton>
|
||||
))}
|
||||
</div>
|
||||
{error && <p className="text-xs text-red-700" role="alert">{error}</p>}
|
||||
{answer && (
|
||||
<div className="space-y-2 rounded border border-violet-200 bg-violet-50/60 p-2 text-sm">
|
||||
<AiNotice />
|
||||
<p className="whitespace-pre-wrap rounded border bg-white p-2">{answer.text}</p>
|
||||
{answer.changes.length > 0 && (
|
||||
<details className="text-xs text-gray-600"><summary className="cursor-pointer">What changed</summary>
|
||||
<ul className="ml-4 mt-1 list-disc">{answer.changes.map(c => <li key={c}>{c}</li>)}</ul>
|
||||
</details>
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
<button type="button" className="rounded bg-brand-600 px-3 py-1 text-xs font-medium text-white hover:bg-brand-700" onClick={() => { onChange(answer.text); setAnswer(null); }}>Use this</button>
|
||||
<button type="button" className="rounded border bg-white px-3 py-1 text-xs hover:bg-gray-50" onClick={() => setAnswer(null)}>Keep mine</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user