Skip to content

Commit

Permalink
feat: add defaults values to existing context
Browse files Browse the repository at this point in the history
  • Loading branch information
atourneriePresta committed Aug 24, 2023
1 parent 3f9dde2 commit b7cc8f5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/PsAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ interface PsAccountsProps {
context?: Context;
}
const props = withDefaults(defineProps<PsAccountsProps>(), {
context: () => window.contextPsAccounts || {}
context: () => (window.contextPsAccounts ? contextSchema.validate(window.contextPsAccounts).value : {}) as Context
});
const errors = ref<string[]>([]);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/ContextValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi';
import { ShopContext } from '@/types/context';

export const backendUserSchema = Joi.object().keys({
email: Joi.string().email({ tlds: false }).allow(null).default(null),
Expand Down Expand Up @@ -55,7 +56,7 @@ export const userSchema = Joi.object().keys({
export const contextSchema = Joi.object().keys({
accountsUiUrl: Joi.string().allow(null).default(null),
backendUser: backendUserSchema.optional().allow({}).default({}),
currentContext: currentContextSchema.optional().allow({}).default({}),
currentContext: currentContextSchema.optional().default({ type: ShopContext.All }),
// dependencies
onboardingLink: Joi.string().uri().optional().allow(null)
.allow('')
Expand Down

0 comments on commit b7cc8f5

Please sign in to comment.