-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: create key toggle issue #2711
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 WalkthroughWalkthroughThe pull request introduces significant modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Thank you for following the naming conventions for pull request titles! 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (4)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)
62-62
: Correct the grammatical error in the commentThe comment contains a grammatical error. It should read: "Required to unregister form elements when they are not rendered."
Apply this diff to correct the comment:
-// Should required to unregister form elements when they are not rendered. +// Required to unregister form elements when they are not rendered.apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts (3)
21-37
: Add conditional validation formeta
based onmetaEnabled
Currently, the
meta
field is validated even whenmetaEnabled
is false. To prevent unnecessary validation and potential user confusion, consider adding conditional logic to validatemeta
only whenmetaEnabled
is true.You can modify the schema as follows:
export const formSchema = z.object({ // ... other fields ... metaEnabled: z.boolean().default(false), - meta: z - .string() - .refine( - (s) => { - try { - JSON.parse(s); - return true; - } catch { - return false; - } - }, - { - message: "Must be valid json", - }, - ) - .optional(), + meta: z.string().optional(), }).superRefine((data, ctx) => { + if (data.metaEnabled) { + if (!data.meta) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ['meta'], + message: 'Metadata is required when meta is enabled.', + }); + } else { + try { + JSON.parse(data.meta); + } catch { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ['meta'], + message: 'Must be valid JSON.', + }); + } + } + } // ... other superRefine logic ... });This ensures that
meta
is only required and validated whenmetaEnabled
is true.
38-83
: Add conditional validation forlimit
based onlimitEnabled
The
limit
field should be validated only whenlimitEnabled
is true. Adding conditional validation enhances form correctness and aligns with user expectations.You can adjust the schema as follows:
export const formSchema = z.object({ // ... other fields ... limitEnabled: z.boolean().default(false), - limit: z - .object({ - // limit fields ... - }) - .optional(), + limit: z.object({ + // limit fields ... + }).optional(), }).superRefine((data, ctx) => { + if (data.limitEnabled) { + if (!data.limit) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ['limit'], + message: 'Limit details are required when Limited Use is enabled.', + }); + } + // Additional conditional validations can be added here + } // ... other superRefine logic ... });This modification ensures
limit
is required and validated only whenlimitEnabled
is true.
84-88
: Add conditional validation forexpires
based onexpireEnabled
To prevent unnecessary validation, ensure that the
expires
field is only validated whenexpireEnabled
is true.Modify the schema as follows:
export const formSchema = z.object({ // ... other fields ... expireEnabled: z.boolean().default(false), - expires: z.coerce - .date() - .min(new Date(new Date().getTime() + 2 * 60000)) - .optional(), + expires: z.coerce.date().optional(), }).superRefine((data, ctx) => { + if (data.expireEnabled) { + if (!data.expires) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ['expires'], + message: 'Expiry date is required when Expiration is enabled.', + }); + } else if (data.expires < new Date(Date.now() + 2 * 60000)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ['expires'], + message: 'Expiry date must be at least 2 minutes in the future.', + }); + } + } // ... other superRefine logic ... });This ensures
expires
is validated only whenexpireEnabled
is true.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx
(4 hunks)apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts
(1 hunks)
🔇 Additional comments (3)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (3)
35-35
: Good use of 'date-fns' for date manipulation
The addition of addMinutes
and format
from date-fns
improves date handling and ensures consistency across date operations.
41-42
: Enhancing modularity by importing the validation schema
Importing formSchema
from './validation'
and typing z
from zod
improves code organization by separating validation logic from the component.
53-53
: Simplify component definition by removing React.FC
Great job simplifying the component definition. Removing the React.FC
type annotation and directly typing props enhances readability and follows current TypeScript best practices.
What does this PR do?
Fixes #2702
Type of change
How should this be tested?
Checklist
Required
pnpm build
pnpm fmt
console.logs
git pull origin main
Appreciated
Summary by CodeRabbit
New Features
CreateKey
component with enhanced form handling and error management.Bug Fixes
Documentation