feat: support user-related placeholders in submission templates and standardize display time to Asia/Bangkok timezone
This commit is contained in:
@@ -113,8 +113,15 @@ export async function submitForm(
|
||||
}, {} as Record<string, string>);
|
||||
|
||||
let message = templateToUse;
|
||||
// Replace {1}, {2}, etc. with value
|
||||
// Replace {1}, {2}, etc. with value, and new variables
|
||||
message = message.replace(/\{([^}]+)\}/g, (match: string, p1: string) => {
|
||||
const key = p1.toLowerCase();
|
||||
if (key === "username" || key === "displayname") {
|
||||
return session.user?.name || "Unknown User";
|
||||
}
|
||||
if (key === "id") {
|
||||
return discordId || "Unknown ID";
|
||||
}
|
||||
return answersDict[p1] || "Not Provided";
|
||||
});
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ export default function FormExtraClient({ form }: FormExtraClientProps) {
|
||||
className="min-h-24"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use <code>{`{1}`}</code>, <code>{`{2}`}</code> to insert answers according to question order. Example: <code>{`{1}`}</code> for the first question.
|
||||
Use <code>{`{1}`}</code>, <code>{`{2}`}</code> to insert answers according to question order, and <code>{`{username}`}</code>, <code>{`{displayname}`}</code>, <code>{`{id}`}</code> for user info.
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
@@ -86,7 +86,7 @@ export default function FormExtraClient({ form }: FormExtraClientProps) {
|
||||
className="min-h-24"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Used when a user updates their existing submission. Use <code>{`{1}`}</code>, <code>{`{2}`}</code> to insert answers.
|
||||
Used when a user updates their existing submission. Use <code>{`{1}`}</code>, <code>{`{2}`}</code> for answers, and <code>{`{username}`}</code>, <code>{`{displayname}`}</code>, <code>{`{id}`}</code> for user info.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex justify-end pt-2">
|
||||
|
||||
@@ -77,14 +77,14 @@ export default function SubmissionDetailClient({
|
||||
<div className="flex items-center gap-2 text-muted-foreground">
|
||||
<Calendar className="w-4 h-4 shrink-0" />
|
||||
<span className="font-semibold text-foreground">Initial Submission:</span>
|
||||
<span>{new Date(submission.submittedAt).toLocaleString(undefined, { hour12: false })}</span>
|
||||
<span>{new Date(submission.submittedAt).toLocaleString("en-US", { timeZone: "Asia/Bangkok", hour12: false })}</span>
|
||||
</div>
|
||||
{editHistory.length > 0 && (
|
||||
<div className="flex flex-col mt-2 pt-2 border-t">
|
||||
<span className="font-semibold text-foreground mb-1">Edit History:</span>
|
||||
<ul className="list-disc list-inside text-xs text-muted-foreground space-y-1">
|
||||
{editHistory.map((edit, idx) => (
|
||||
<li key={idx}>Edited at {new Date(edit.editedAt).toLocaleString(undefined, { hour12: false })}</li>
|
||||
<li key={idx}>Edited at {new Date(edit.editedAt).toLocaleString("en-US", { timeZone: "Asia/Bangkok", hour12: false })}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
@@ -197,7 +197,7 @@ export default function SubmissionDetailClient({
|
||||
>
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<Clock className="w-3 h-3 shrink-0" />
|
||||
<span>{new Date(entry.editedAt).toLocaleString()}</span>
|
||||
<span>{new Date(entry.editedAt).toLocaleString("en-US", { timeZone: "Asia/Bangkok", hour12: false })}</span>
|
||||
</div>
|
||||
<span className="text-sm text-foreground/80 whitespace-pre-wrap leading-relaxed">
|
||||
{entry.answer || <span className="italic text-muted-foreground">No response</span>}
|
||||
|
||||
@@ -81,7 +81,7 @@ export default async function ResultsListPage(
|
||||
</TableCell>
|
||||
<TableCell className="p-0 text-muted-foreground">
|
||||
<Link href={`/admin/form/${params.id}/result/${sub.id}`} className="flex items-center p-4 w-full h-full">
|
||||
{new Date(sub.submittedAt).toLocaleString()}
|
||||
{new Date(sub.submittedAt).toLocaleString("en-US", { timeZone: "Asia/Bangkok", hour12: false })}
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="text-right p-4">
|
||||
|
||||
Reference in New Issue
Block a user