From 325e21a46d5ba67edda576413cfaf869482e7910 Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Fri, 11 Apr 2025 17:20:02 +0000 Subject: [PATCH] Enhance API token creation: Add custom time selection and improved error handling. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/4b83cb21-3b79-40aa-b094-7a80de76ff82.jpg --- client/src/pages/api-tokens.tsx | 72 ++++++++++++++++----------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/client/src/pages/api-tokens.tsx b/client/src/pages/api-tokens.tsx index 15d3fc8..f52ee56 100644 --- a/client/src/pages/api-tokens.tsx +++ b/client/src/pages/api-tokens.tsx @@ -80,6 +80,15 @@ const tokenFormSchema = z.object({ expiresIn: z.string().optional(), customDate: z.date().optional(), customTime: z.string().optional(), +}).refine((data) => { + // If custom expiration is selected, a date must be provided + if (data.expiresIn === 'custom' && !data.customDate) { + return false; + } + return true; +}, { + message: "Please select a date for the custom expiration", + path: ["customDate"] }); export default function ApiTokensPage() { @@ -136,7 +145,13 @@ export default function ApiTokensPage() { // If time was selected, add it to the date if (data.customTime) { const [hours, minutes] = data.customTime.split(':').map(Number); - customDate.setHours(hours, minutes, 0, 0); + // Check if hours and minutes are valid numbers + if (!isNaN(hours) && !isNaN(minutes)) { + customDate.setHours(hours, minutes, 0, 0); + } else { + // Default to end of day if time format is invalid + customDate.setHours(23, 59, 59, 999); + } } else { // Default to end of day if no time selected customDate.setHours(23, 59, 59, 999); @@ -516,44 +531,25 @@ export default function ApiTokensPage() { render={({ field }) => ( Custom Time - + +
+ +
+ + + {field.value ? field.value : "23:59"} + +
+
+
- The time when the token will expire + The exact time (HH:MM) when the token will expire