260623_01_ENH: 엑셀 다운로드를 제외한 기능 완성
This commit is contained in:
4
src/lib/gwcf/date.ts
Normal file
4
src/lib/gwcf/date.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const toLocalDateString = (date = new Date()) => {
|
||||
const pad = (value: number) => String(value).padStart(2, "0");
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
||||
};
|
||||
75
src/lib/gwcf/file.ts
Normal file
75
src/lib/gwcf/file.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import {downloadFile} from "@/lib/utils";
|
||||
import {buildWrittenReviewLink} from "@/config/gwcf.config";
|
||||
|
||||
const REVIEW_TIMESTAMP_PREFIX = /^\d{4}-\d{2}-\d{2}_\d{6}_/;
|
||||
|
||||
export const removeTimestampPrefix = (fileName?: string) =>
|
||||
fileName?.replace(REVIEW_TIMESTAMP_PREFIX, "");
|
||||
|
||||
export const downloadBlob = (
|
||||
buffer: ArrayBuffer,
|
||||
fileName: string,
|
||||
type = "application/octet-stream"
|
||||
) => {
|
||||
downloadFile(new Blob([buffer], {type}), fileName);
|
||||
};
|
||||
|
||||
export const downloadExcelBuffer = (buffer: ArrayBuffer, fileName: string) => {
|
||||
downloadBlob(buffer, fileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
};
|
||||
|
||||
export const downloadFromUrl = (url: string) => {
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
};
|
||||
|
||||
export const getReviewOriginalDownloadName = (
|
||||
performanceId: number,
|
||||
reviewType: number,
|
||||
uploadFileName?: string
|
||||
) => removeTimestampPrefix(uploadFileName) || `review-original-${performanceId}-${reviewType}`;
|
||||
|
||||
export const getReviewPdfDownloadName = (
|
||||
performanceId: number,
|
||||
reviewType: number,
|
||||
pdfFileName?: string
|
||||
) => removeTimestampPrefix(pdfFileName) || `review-pdf-${performanceId}-${reviewType}.pdf`;
|
||||
|
||||
export const getEvidenceZipDownloadName = (performanceId: number, userId: string) =>
|
||||
`도착 증빙_${performanceId}_${userId}.zip`;
|
||||
|
||||
export const buildReviewPdfPreviewUrl = (
|
||||
performanceId: number,
|
||||
reviewType: number,
|
||||
userId: string,
|
||||
title?: string
|
||||
) => {
|
||||
const src = `/api/review/pdf/${performanceId}/${reviewType}/${encodeURIComponent(userId)}?disposition=inline`;
|
||||
return `/file-preview?type=pdf&src=${encodeURIComponent(src)}&title=${encodeURIComponent(title || getReviewPdfDownloadName(performanceId, reviewType))}`;
|
||||
};
|
||||
|
||||
export const buildEvidenceImageSrc = (
|
||||
performanceId: number,
|
||||
userId: string,
|
||||
fileName: string
|
||||
) => `/api/file/visit/${performanceId}/${encodeURIComponent(userId)}/${encodeURIComponent(fileName)}`;
|
||||
|
||||
export const buildImagePreviewUrl = (title: string, images: string[]) =>
|
||||
`/file-preview?type=image&title=${encodeURIComponent(title)}&images=${encodeURIComponent(JSON.stringify(images))}`;
|
||||
|
||||
export const openPreviewWindow = (url: string) => {
|
||||
window.open(url, "_blank", "noopener,noreferrer");
|
||||
};
|
||||
|
||||
export const openWrittenReviewWindow = (
|
||||
performanceId: number,
|
||||
userId: string | undefined,
|
||||
complete = false
|
||||
) => {
|
||||
if (!userId) return;
|
||||
window.open(buildWrittenReviewLink({performanceId, userId, complete}), "_blank", "noopener,noreferrer");
|
||||
};
|
||||
35
src/lib/gwcf/notification.ts
Normal file
35
src/lib/gwcf/notification.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {PerformanceFull, UserCompact} from "@/types/gwcf";
|
||||
|
||||
export const toNotificationParamValue = (value: unknown) => value == null ? "" : String(value);
|
||||
|
||||
export const buildUserMsgParam = (user: UserCompact): Record<string, string> => ({
|
||||
...Object.fromEntries(
|
||||
Object.entries(user.userDetail ?? {}).map(([key, value]) => [key, toNotificationParamValue(value)])
|
||||
),
|
||||
userId: toNotificationParamValue(user.userId),
|
||||
userCmpn: toNotificationParamValue(user.userCmpn),
|
||||
userTeam: toNotificationParamValue(user.userTeam),
|
||||
userName: toNotificationParamValue(user.userName),
|
||||
userRole: toNotificationParamValue(user.userRole),
|
||||
});
|
||||
|
||||
export const buildPerformanceSmsParams = (performance: PerformanceFull): Record<string, string> => ({
|
||||
businessType: toNotificationParamValue(performance.businessType),
|
||||
performanceGenre: toNotificationParamValue(performance.performanceGenre),
|
||||
performanceArea: toNotificationParamValue(performance.performanceArea),
|
||||
artistName: toNotificationParamValue(performance.artistName),
|
||||
performanceName: toNotificationParamValue(performance.performanceName),
|
||||
performanceStartMonth: toNotificationParamValue(performance.performanceStartMonth),
|
||||
performanceDtInfo: toNotificationParamValue(performance.performanceDtInfo),
|
||||
performanceTimeInfo: toNotificationParamValue(performance.performanceTimeInfo),
|
||||
ticketReservationStatus: toNotificationParamValue(performance.ticketReservationStatus),
|
||||
ticketReservationMemo: toNotificationParamValue(performance.ticketReservationMemo),
|
||||
performanceMemo: toNotificationParamValue(performance.performanceMemo),
|
||||
...Object.fromEntries(
|
||||
Object.entries(performance.performanceDetail ?? {}).map(([key, value]) => [key, toNotificationParamValue(value)])
|
||||
),
|
||||
...Object.fromEntries(
|
||||
Object.entries(performance.performanceMonitoringSchedule ?? {}).map(([key, value]) => [key, toNotificationParamValue(value)])
|
||||
),
|
||||
performanceId: toNotificationParamValue(performance.id),
|
||||
});
|
||||
@@ -1,14 +1,37 @@
|
||||
import {PerformanceAssign, PerformanceFull, PerformanceMonitoringVisit, PerformanceReview, UserCompact} from "@/types/gwcf";
|
||||
import {Code, PerformanceAssign, PerformanceFull, PerformanceMonitoringVisit, PerformanceReview, UserCompact} from "@/types/gwcf";
|
||||
import type {StatusPillVariant} from "@/components/gwcf/StatusPill";
|
||||
|
||||
export const LOCAL_GOVERNMENT_REVIEW_TYPE = 3;
|
||||
export const MONITORING_ASSIGN_TYPE = 1;
|
||||
export const WRITTEN_REVIEW_ASSIGN_TYPE = 2;
|
||||
export const MONITORING_DEPARTURE_STATUS = 2;
|
||||
export const MONITORING_ARRIVAL_STATUS = 3;
|
||||
|
||||
export type MonitoringVisitTimeline = {
|
||||
departure?: PerformanceMonitoringVisit;
|
||||
arrival?: PerformanceMonitoringVisit;
|
||||
};
|
||||
|
||||
export type MonitoringSlot = {
|
||||
assign?: PerformanceAssign;
|
||||
user?: UserCompact;
|
||||
visit?: PerformanceMonitoringVisit;
|
||||
visit?: PerformanceMonitoringVisit[];
|
||||
timeline: MonitoringVisitTimeline;
|
||||
};
|
||||
|
||||
export type ReviewDisplayRow = {
|
||||
userId: string;
|
||||
assign?: PerformanceAssign;
|
||||
review?: PerformanceReview;
|
||||
};
|
||||
|
||||
export type MonitoringDisplayRow = {
|
||||
index: 0 | 1;
|
||||
reviewType: number;
|
||||
slot: MonitoringSlot;
|
||||
userId?: string;
|
||||
evidenceUserId?: string;
|
||||
review?: PerformanceReview;
|
||||
};
|
||||
|
||||
export type StatusDisplay = {
|
||||
@@ -16,6 +39,59 @@ export type StatusDisplay = {
|
||||
variant: StatusPillVariant;
|
||||
};
|
||||
|
||||
export const STATUS_FILTER = {
|
||||
UNASSIGNED: "-1001",
|
||||
INCOMPLETE: "-1002",
|
||||
PENDING: "-1003",
|
||||
IN_PROGRESS: "-1004",
|
||||
DEPARTED: "-1005",
|
||||
ARRIVED: "-1006",
|
||||
DONE: "-1007",
|
||||
} as const;
|
||||
|
||||
export const makeStatusOption = (value: string, label: string): Code => ({
|
||||
codeGroup: "status_filter",
|
||||
codeValue: Number(value),
|
||||
codeGroupLabel: "상태",
|
||||
codeLabel: label,
|
||||
memo: "",
|
||||
});
|
||||
|
||||
export const statusFilterOptions = {
|
||||
incomplete: makeStatusOption(STATUS_FILTER.INCOMPLETE, "미완료"),
|
||||
pending: makeStatusOption(STATUS_FILTER.PENDING, "미진행"),
|
||||
inProgress: makeStatusOption(STATUS_FILTER.IN_PROGRESS, "진행중"),
|
||||
departed: makeStatusOption(STATUS_FILTER.DEPARTED, "출발"),
|
||||
arrived: makeStatusOption(STATUS_FILTER.ARRIVED, "도착"),
|
||||
done: makeStatusOption(STATUS_FILTER.DONE, "완료"),
|
||||
};
|
||||
|
||||
export const normalizeStatusLabel = (label?: string) => label?.replace(/\s/g, "") ?? "";
|
||||
export const labelHasInProgress = (label?: string) => normalizeStatusLabel(label).includes("진행");
|
||||
export const labelHasDeparted = (label?: string) => normalizeStatusLabel(label).includes("출발");
|
||||
export const labelHasArrived = (label?: string) => normalizeStatusLabel(label).includes("도착");
|
||||
export const labelHasComplete = (label?: string) => normalizeStatusLabel(label).includes("완료");
|
||||
|
||||
const sortMonitoringVisits = (visits: PerformanceMonitoringVisit[]) => {
|
||||
return [...visits].sort((a, b) => {
|
||||
if (b.monitoringVisitStatus !== a.monitoringVisitStatus) {
|
||||
return b.monitoringVisitStatus - a.monitoringVisitStatus;
|
||||
}
|
||||
return new Date(b.regDt ?? 0).getTime() - new Date(a.regDt ?? 0).getTime();
|
||||
});
|
||||
};
|
||||
|
||||
const getMonitoringVisits = (visits: PerformanceMonitoringVisit[], userId?: string) => {
|
||||
const matchedVisits = userId ? visits.filter((item) => item.regUser === userId) : visits;
|
||||
const candidates = matchedVisits.length > 0 ? matchedVisits : visits;
|
||||
return sortMonitoringVisits(candidates);
|
||||
};
|
||||
|
||||
const getMonitoringTimeline = (visits: PerformanceMonitoringVisit[]): MonitoringVisitTimeline => ({
|
||||
departure: visits.find((visit) => visit.monitoringVisitStatus === MONITORING_DEPARTURE_STATUS),
|
||||
arrival: visits.find((visit) => visit.monitoringVisitStatus === MONITORING_ARRIVAL_STATUS),
|
||||
});
|
||||
|
||||
export const getMonitoringSlots = (performance: Partial<PerformanceFull>): [MonitoringSlot, MonitoringSlot] => {
|
||||
const confirmedAssigns = (performance.performanceAssignList ?? [])
|
||||
.filter((assign) => assign.assignType === MONITORING_ASSIGN_TYPE && assign.assignConfirm)
|
||||
@@ -26,11 +102,9 @@ export const getMonitoringSlots = (performance: Partial<PerformanceFull>): [Moni
|
||||
return [0, 1].map((index) => {
|
||||
const assign = confirmedAssigns[index];
|
||||
const userVisits = assign ? visits[assign.assignUser] ?? [] : [];
|
||||
const visit = assign
|
||||
? userVisits.find((item) => item.regUser === assign.assignUser) ?? userVisits[0]
|
||||
: undefined;
|
||||
const sortedVisits = assign ? getMonitoringVisits(userVisits, assign.assignUser) : [];
|
||||
|
||||
return {assign, visit};
|
||||
return {assign, visit: sortedVisits, timeline: getMonitoringTimeline(sortedVisits)};
|
||||
}) as [MonitoringSlot, MonitoringSlot];
|
||||
};
|
||||
|
||||
@@ -49,21 +123,55 @@ export const getReviewRows = (performance: Partial<PerformanceFull>) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getWrittenReviewRows = (performance: Partial<PerformanceFull>) => {
|
||||
const reviewRows = getReviewRows(performance).filter(({review}) => review.reviewType !== LOCAL_GOVERNMENT_REVIEW_TYPE);
|
||||
export const getMonitoringReviewByIndex = (
|
||||
performance: Partial<PerformanceFull>,
|
||||
index: 0 | 1,
|
||||
slot?: MonitoringSlot
|
||||
) => {
|
||||
const assignedUserId = slot?.assign?.assignUser;
|
||||
const assignedReview = assignedUserId
|
||||
? (performance.performanceReviewMap?.[assignedUserId] ?? []).find((review) => review.reviewType === MONITORING_ASSIGN_TYPE)
|
||||
: undefined;
|
||||
|
||||
return assignedReview && assignedUserId
|
||||
? {userId: assignedUserId, review: assignedReview}
|
||||
: undefined;
|
||||
};
|
||||
|
||||
export const getMonitoringDisplayRow = (
|
||||
performance: Partial<PerformanceFull>,
|
||||
index: 0 | 1
|
||||
): MonitoringDisplayRow => {
|
||||
const slot = getMonitoringSlots(performance)[index];
|
||||
const reviewRow = getMonitoringReviewByIndex(performance, index, slot);
|
||||
const visit = slot.visit?.[0];
|
||||
|
||||
return {
|
||||
index,
|
||||
reviewType: MONITORING_ASSIGN_TYPE,
|
||||
slot,
|
||||
userId: slot.assign?.assignUser,
|
||||
evidenceUserId: slot.timeline.arrival?.regUser || visit?.regUser || slot.assign?.assignUser,
|
||||
review: reviewRow?.review,
|
||||
};
|
||||
};
|
||||
|
||||
export const getWrittenReviewRows = (performance: Partial<PerformanceFull>): ReviewDisplayRow[] => {
|
||||
const writtenAssigns = (performance.performanceAssignList ?? [])
|
||||
.filter((assign) => assign.assignType === WRITTEN_REVIEW_ASSIGN_TYPE);
|
||||
const assignedUserIds = writtenAssigns.map((assign) => assign.assignUser);
|
||||
|
||||
const reviewRows = getReviewRows(performance).filter(({userId, review}) =>
|
||||
review.reviewType === WRITTEN_REVIEW_ASSIGN_TYPE &&
|
||||
assignedUserIds.includes(userId)
|
||||
);
|
||||
|
||||
const reviewByUser = new Map(reviewRows.map((row) => [row.userId, row.review]));
|
||||
|
||||
const assignedUserIds = (performance.performanceAssignList ?? [])
|
||||
.filter((assign) => assign.assignType !== MONITORING_ASSIGN_TYPE)
|
||||
.map((assign) => assign.assignUser);
|
||||
|
||||
const userIds = Array.from(new Set([...assignedUserIds, ...reviewRows.map((row) => row.userId)]));
|
||||
|
||||
return userIds.map((userId) => ({
|
||||
userId,
|
||||
assign: (performance.performanceAssignList ?? []).find(
|
||||
(assign) => assign.assignType !== MONITORING_ASSIGN_TYPE && assign.assignUser === userId
|
||||
),
|
||||
assign: writtenAssigns.find((assign) => assign.assignUser === userId),
|
||||
review: reviewByUser.get(userId),
|
||||
}));
|
||||
};
|
||||
@@ -88,10 +196,35 @@ export const getMonitoringRecordedUser = (visit?: PerformanceMonitoringVisit) =>
|
||||
};
|
||||
|
||||
export const isReviewComplete = (review?: PerformanceReview) => {
|
||||
return Boolean(review?.pdfFileName || review?.pdfConvert);
|
||||
return review?.reviewStatus === 10;
|
||||
};
|
||||
|
||||
const normalizeStatusLabel = (label?: string) => label?.replace(/\s/g, "") ?? "";
|
||||
export const getReviewFilterValue = (
|
||||
review: PerformanceReview | undefined,
|
||||
label: string | undefined,
|
||||
{
|
||||
isWrittenReviewer = false,
|
||||
allowInProgress = false,
|
||||
assigned = Boolean(review),
|
||||
alwaysAssigned = false,
|
||||
}: {
|
||||
isWrittenReviewer?: boolean;
|
||||
allowInProgress?: boolean;
|
||||
assigned?: boolean;
|
||||
alwaysAssigned?: boolean;
|
||||
} = {}
|
||||
) => {
|
||||
if (isWrittenReviewer) {
|
||||
return isReviewComplete(review)
|
||||
? STATUS_FILTER.DONE
|
||||
: STATUS_FILTER.INCOMPLETE;
|
||||
}
|
||||
|
||||
if (!alwaysAssigned && !assigned && !review) return STATUS_FILTER.UNASSIGNED;
|
||||
if (isReviewComplete(review)) return STATUS_FILTER.DONE;
|
||||
if (allowInProgress && labelHasInProgress(label)) return STATUS_FILTER.IN_PROGRESS;
|
||||
return STATUS_FILTER.PENDING;
|
||||
};
|
||||
|
||||
export const getReviewStatusDisplay = (
|
||||
label?: string,
|
||||
@@ -107,6 +240,14 @@ export const getReviewStatusDisplay = (
|
||||
return {label: label || "미진행", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getReviewRecordedAt = (review?: PerformanceReview) => {
|
||||
return review?.reviewDt ? formatDateTime(new Date(review.reviewDt)) : "-";
|
||||
}
|
||||
|
||||
export const getCompleteRecordedAt = (review?: PerformanceReview) => {
|
||||
return isReviewComplete(review) ? getReviewRecordedAt(review) : "-";
|
||||
}
|
||||
|
||||
export const getWrittenReviewerSimpleReviewStatusDisplay = (
|
||||
review?: PerformanceReview,
|
||||
allowInProgress = false,
|
||||
@@ -121,15 +262,29 @@ export const getWrittenReviewerSimpleReviewStatusDisplay = (
|
||||
return {label: "미완료", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getWrittenReviewerSimpleMonitoringStatusDisplay = (slot?: MonitoringSlot): StatusDisplay => {
|
||||
return slot?.visit
|
||||
? {label: "완료", variant: "done"}
|
||||
: {label: "미완료", variant: "pending"};
|
||||
export const getMonitoringFilterValue = (
|
||||
row: MonitoringDisplayRow,
|
||||
visitLabel: string | undefined,
|
||||
reviewLabel: string | undefined,
|
||||
isWrittenReviewer = false
|
||||
) => {
|
||||
if (isWrittenReviewer) {
|
||||
return isReviewComplete(row.review)
|
||||
? STATUS_FILTER.DONE
|
||||
: STATUS_FILTER.INCOMPLETE;
|
||||
}
|
||||
|
||||
if (isReviewComplete(row.review)) return STATUS_FILTER.DONE;
|
||||
if (!row.slot.assign && !row.slot.visit?.length) return STATUS_FILTER.UNASSIGNED;
|
||||
if (!row.slot.visit?.length) return STATUS_FILTER.PENDING;
|
||||
if (labelHasDeparted(visitLabel)) return STATUS_FILTER.DEPARTED;
|
||||
if (labelHasArrived(visitLabel)) return STATUS_FILTER.ARRIVED;
|
||||
return STATUS_FILTER.PENDING;
|
||||
};
|
||||
|
||||
export const getMonitoringStatusDisplay = (label?: string, slot?: MonitoringSlot): StatusDisplay => {
|
||||
if (!slot?.assign) return {label: "미배치", variant: "danger"};
|
||||
if (!slot.visit) return {label: "미진행", variant: "pending"};
|
||||
if (!slot?.assign && !slot?.visit?.length) return {label: "미배치", variant: "danger"};
|
||||
if (!slot?.visit?.length) return {label: "미진행", variant: "pending"};
|
||||
|
||||
const normalized = normalizeStatusLabel(label);
|
||||
if (normalized.includes("완료")) return {label: label || "완료", variant: "done"};
|
||||
@@ -139,6 +294,22 @@ export const getMonitoringStatusDisplay = (label?: string, slot?: MonitoringSlot
|
||||
return {label: label || "미진행", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getMonitoringDisplayStatus = (
|
||||
row: MonitoringDisplayRow,
|
||||
visitLabel?: string,
|
||||
reviewLabel?: string,
|
||||
isWrittenReviewer = false
|
||||
): StatusDisplay => {
|
||||
if (isWrittenReviewer) {
|
||||
return isReviewComplete(row.review)
|
||||
? {label: "완료", variant: "done"}
|
||||
: {label: "미완료", variant: "pending"};
|
||||
}
|
||||
|
||||
if (isReviewComplete(row.review)) return {label: reviewLabel || "완료", variant: "done"};
|
||||
return getMonitoringStatusDisplay(visitLabel, row.slot);
|
||||
};
|
||||
|
||||
export const getAssignStatusDisplay = (confirmed: boolean): StatusDisplay => {
|
||||
return confirmed
|
||||
? {label: "확정", variant: "done"}
|
||||
|
||||
@@ -102,6 +102,20 @@ const isJsonContentType = (ctype: string) => {
|
||||
return ct.includes("application/json") || ct.includes("+json")
|
||||
}
|
||||
|
||||
const getErrorMessage = (data: unknown) => {
|
||||
if (typeof data === "object" && data !== null) {
|
||||
const error = data as { detail?: unknown; message?: unknown; errMessage?: unknown };
|
||||
return (
|
||||
(typeof error.detail === "string" && error.detail) ||
|
||||
(typeof error.message === "string" && error.message) ||
|
||||
(typeof error.errMessage === "string" && error.errMessage) ||
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
return typeof data === "string" && data ? data : undefined;
|
||||
};
|
||||
|
||||
export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {}) => {
|
||||
const {
|
||||
getToken,
|
||||
@@ -179,7 +193,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
|
||||
}
|
||||
|
||||
const autoLogout = options.autoLogoutOnAuthError ?? true;
|
||||
const suppressAlert = options.suppressAlert ?? true;
|
||||
const suppressAlert = options.suppressAlert ?? options.method === "GET";
|
||||
|
||||
if (res.status === 401) options.onAuthError?.();
|
||||
|
||||
@@ -191,12 +205,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
|
||||
}
|
||||
|
||||
if (!suppressAlert && typeof window !== "undefined") {
|
||||
const serverMsg =
|
||||
typeof parsedError === "object" && parsedError !== null && "message" in parsedError
|
||||
? String((parsedError as { message?: unknown }).message ?? "")
|
||||
: typeof parsedError === "string"
|
||||
? parsedError
|
||||
: undefined;
|
||||
const serverMsg = getErrorMessage(parsedError);
|
||||
|
||||
const msg = setErrorMessage?.(res.status, serverMsg) ?? (serverMsg ?? `HTTP ${res.status}`);
|
||||
alert(`[${res.status}] ${msg}`);
|
||||
@@ -223,7 +232,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
|
||||
|
||||
if (!res.ok) {
|
||||
const autoLogout = options.autoLogoutOnAuthError ?? true;
|
||||
const suppressAlert = options.suppressAlert ?? true;
|
||||
const suppressAlert = options.suppressAlert ?? options.method === "GET";
|
||||
|
||||
if (res.status === 401) options.onAuthError?.();
|
||||
|
||||
@@ -235,12 +244,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
|
||||
}
|
||||
|
||||
if (!suppressAlert && typeof window !== "undefined") {
|
||||
const serverMsg =
|
||||
typeof parsed === "object" && parsed !== null && "message" in parsed
|
||||
? String((parsed as { message?: unknown }).message ?? "")
|
||||
: typeof parsed === "string"
|
||||
? parsed
|
||||
: undefined;
|
||||
const serverMsg = getErrorMessage(parsed);
|
||||
|
||||
const msg = setErrorMessage?.(res.status, serverMsg) ?? (serverMsg ?? `HTTP ${res.status}`);
|
||||
alert(`[${res.status}] ${msg}`);
|
||||
|
||||
Reference in New Issue
Block a user