Skip to content
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

Merged
merged 5 commits into from
Aug 5, 2024

Conversation

Dhanush295
Copy link
Contributor

Add validation and fallback for featured links in general settings #31

@Dhanush295
Copy link
Contributor Author

fix: save featured links with validation

src/components/admin/settings/general/Update.vue Outdated Show resolved Hide resolved
Comment on lines 70 to 72
const validLinks = featuredLinks.value
.filter(link => link.url && isValidUrl(link.url))
.map(link => ({ name: link.name || link.url, url: link.url }));
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated bro!

Comment on lines 52 to 55
featuredLinks.value = (gs.organization.links || []).map(link => ({
name: link.name || link.url,
url: link.url
}));
Copy link
Member

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 || []

Copy link
Contributor Author

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 ???

Copy link
Member

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: [] }', 
     }, 

await db.insert(metaDataTable).values([
{
key: 'seoConfig',
value: '{}',
},
{
key: 'organizationConfig',
value: '{}',
},
]);
};

Then clear your database and restart server. This will initialise the array.

Copy link
Contributor Author

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">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@amandesai01 amandesai01 merged commit cbce819 into profilecity:main Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants