690331:1616 Correspondence Page Refactor by GPT-5.3-Codex Medium #03
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useSession, signOut } from 'next-auth/react';
|
||||
import { useEffect } from 'react';
|
||||
import { useAuthStore } from '@/lib/stores/auth-store';
|
||||
import { clearAuthTokenCache } from '@/lib/api/client';
|
||||
|
||||
export function AuthSync() {
|
||||
const { data: session, status } = useSession();
|
||||
@@ -10,6 +11,7 @@ export function AuthSync() {
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.error === 'RefreshAccessTokenError') {
|
||||
clearAuthTokenCache(); // Clear cached token on auth error
|
||||
signOut({ callbackUrl: '/login' });
|
||||
} else if (status === 'authenticated' && session?.user) {
|
||||
// Map NextAuth session to AuthStore user
|
||||
@@ -40,6 +42,7 @@ export function AuthSync() {
|
||||
(session as { accessToken?: string }).accessToken || ''
|
||||
);
|
||||
} else if (status === 'unauthenticated') {
|
||||
clearAuthTokenCache(); // Clear cached token on logout
|
||||
logout();
|
||||
}
|
||||
}, [session, status, setAuth, logout]);
|
||||
|
||||
@@ -25,15 +25,6 @@ interface CorrespondenceDetailProps {
|
||||
selectedRevisionId?: string;
|
||||
}
|
||||
|
||||
const normalizeUuid = (value?: string): string | undefined => {
|
||||
if (typeof value !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const normalized = value.trim().toLowerCase();
|
||||
return normalized.length > 0 ? normalized : undefined;
|
||||
};
|
||||
|
||||
const normalizeRecipientType = (value?: string): string | undefined => {
|
||||
if (typeof value !== 'string') {
|
||||
return undefined;
|
||||
@@ -54,9 +45,9 @@ export function CorrespondenceDetail({ data, selectedRevisionId }: Correspondenc
|
||||
|
||||
if (!data) return <div>No data found</div>;
|
||||
|
||||
const normalizedSelectedRevisionId = normalizeUuid(selectedRevisionId);
|
||||
const selectedRevision = normalizedSelectedRevisionId
|
||||
? data.revisions?.find((r) => normalizeUuid(r.publicId) === normalizedSelectedRevisionId)
|
||||
// เลือก revision ตาม selectedRevisionId ถ้ามี ถ้าไม่มีใช้ revision ปัจจุบัน
|
||||
const selectedRevision = selectedRevisionId
|
||||
? data.revisions?.find((r) => r.publicId === selectedRevisionId)
|
||||
: undefined;
|
||||
const currentRevision = selectedRevision || data.revisions?.find((r) => r.isCurrent) || data.revisions?.[0];
|
||||
const subject = currentRevision?.subject || '-';
|
||||
|
||||
Reference in New Issue
Block a user