Files
co-lite/solvway-admin-portal/app/components/messages/NewMessageDialog.tsx
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

87 lines
3.6 KiB
TypeScript

"use client";
import { useState } from "react";
import { Button } from "@/app/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/app/components/ui/dialog";
import { Textarea } from "@/app/components/ui/textarea";
import { ImageAttachments, useAttachments } from "@/app/components/messages/ImageAttachments";
import { MemberSearch } from "@/app/components/messages/MemberSearch";
import { useT } from "@/app/lib/i18n/MessagesProvider";
import { MAX_BODY, messageErrorText, startAdminConversation } from "@/app/lib/services/adminMessages";
import type { AdminMember } from "@/app/lib/types";
// Admin -> member: opens or reuses the member's support (S) thread. Mutation on an explicit click only.
export function NewMessageDialog({
onClose,
onOpened,
initialMember,
initialBody,
}: {
onClose: () => void;
onOpened: (conversationUuid: string) => void;
/** Deep link: member code to message, skipping the search step. */
initialMember?: string;
initialBody?: string;
}) {
const t = useT();
// ponytail: a deep-linked member shows by code only (no name lookup); upgrade by fetching the member if the name is wanted.
const [member, setMember] = useState<AdminMember | null>(initialMember ? ({ memberCode: initialMember } as AdminMember) : null);
const [body, setBody] = useState(initialBody ?? "");
const [sending, setSending] = useState(false);
const [error, setError] = useState<string | null>(null);
const attachments = useAttachments();
const canSend = !!member && !sending && !attachments.busy && body.length <= MAX_BODY && (body.trim() !== "" || attachments.refs.length > 0);
const send = async () => {
if (!member) return;
setSending(true);
setError(null);
try {
const r = await startAdminConversation(member.memberCode, body.trim(), attachments.refs);
onOpened(r.conversationUuid);
} catch (e) {
setError(messageErrorText(e, t));
setSending(false);
}
};
return (
<Dialog open onOpenChange={(open) => !open && !sending && onClose()}>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle>{t("MsgNewMessage")}</DialogTitle>
<DialogDescription>{t("MsgNewMessageHint")}</DialogDescription>
</DialogHeader>
{member ? (
<>
<div className="flex items-center justify-between rounded-md border px-3 py-2 text-sm">
<span>{member.name ?? "—"} · {member.memberCode}</span>
<Button
variant="ghost"
size="sm"
disabled={sending}
onClick={() => {
// A draft (and images) written for one member must not carry over to another.
setMember(null);
setBody("");
setError(null);
attachments.reset();
}}
>
{t("MsgChangeMember")}
</Button>
</div>
<Textarea aria-label={t("MsgBodyLabel")} value={body} maxLength={MAX_BODY} readOnly={sending} onChange={(e) => setBody(e.target.value)} />
<div className="text-xs text-muted-foreground">{body.length}/{MAX_BODY}</div>
<ImageAttachments attachments={attachments} disabled={sending} />
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
<Button onClick={send} disabled={!canSend}>{t("MsgSend")}</Button>
</>
) : (
<MemberSearch onPick={setMember} />
)}
</DialogContent>
</Dialog>
);
}