-
Notifications
You must be signed in to change notification settings - Fork 94
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
save featured links with validation #31 #48
save featured links with validation #31 #48
Conversation
fix: save featured links with validation |
const validLinks = featuredLinks.value | ||
.filter(link => link.url && isValidUrl(link.url)) | ||
.map(link => ({ name: link.name || link.url, url: link.url })); |
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.
it must be validated through zod schema which needs to go into ~/src/schema/settings
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.
Yes, the formSchema with toTypedSchema(generalSettingsSchema) is validated using a Zod schema, which is defined in ~/src/schemas/setting file.
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.
do not validate like this. it should go through existing validation pattern only. see: https://vee-validate.logaretm.com/v4/guide/composition-api/nested-objects-and-arrays/
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.
updated bro!
featuredLinks.value = (gs.organization.links || []).map(link => ({ | ||
name: link.name || link.url, | ||
url: link.url | ||
})); |
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.
you don't need this, just take care of it while saving. also, we can guarantee array initialisation by including in SEED FN (see src/server/tasks/seed-database) so need to do || []
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.
featuredLinks.value = gs.organization.links.map(link => ({name: link.name || link.url, url: link.url }));
So i removed || [] . But the + button is not able to add new rows. Should i keep (gs.organization.links || []).map ???
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.
I am saying you will have to fix that by modifying seed.
Replace below with
{
key: 'organizationConfig',
value: '{ links: [] }',
},
vidur/src/server/utils/seeds.ts
Lines 11 to 22 in 6dcba1e
await db.insert(metaDataTable).values([ | |
{ | |
key: 'seoConfig', | |
value: '{}', | |
}, | |
{ | |
key: 'organizationConfig', | |
value: '{}', | |
}, | |
]); | |
}; | |
Then clear your database and restart server. This will initialise the array.
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.
updated bro!
@@ -153,7 +191,7 @@ const onSubmit = handleSubmit(async values => { | |||
</div> | |||
<!-- Panel footer --> | |||
<footer> | |||
<div class="flex w-full justify-start mb-10 mt-4"> | |||
<div class="flex w-full justify-start mb-10 mt-4"> |
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.
undo this
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.
ok
Add validation and fallback for featured links in general settings #31