add & edit time rezerv

This commit is contained in:
2026-05-25 20:22:51 +03:30
parent 2a25727ef1
commit 833b7589d2
3 changed files with 34 additions and 5 deletions
+13 -3
View File
@@ -40,9 +40,19 @@ export async function api<T>(path: string, options: ApiOptions = {}): Promise<T>
const body = (await res.json().catch(() => null)) as
| { message?: string | string[] }
| null;
const msg = Array.isArray(body?.message)
? body.message.join(', ')
: body?.message ?? res.statusText;
let msg: string;
if (Array.isArray(body?.message)) {
const lines = body.message.map(String);
const timeErrors = lines.filter((l) =>
/startTime|endTime/.test(l) && /regular expression|HH:mm/i.test(l),
);
msg =
timeErrors.length > 0
? 'فرمت ساعت نامعتبر است. لطفاً دوباره بازه را اضافه و ذخیره کنید.'
: lines.join(' · ');
} else {
msg = body?.message ?? res.statusText;
}
throw new ApiError(res.status, msg);
}