Skip to content

Commit

Permalink
Merge pull request #36 from PrestaShopCorp/feature/simplify-presenter
Browse files Browse the repository at this point in the history
remove duplicate logic
  • Loading branch information
david-piatek authored Jul 31, 2020
2 parents fea2513 + 7374d7f commit 0046bd3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prestashop_accounts_vue_components",
"version": "1.0.1",
"version": "1.1.0",
"main": "./dist/psaccountsVue.common.js",
"files": [
"dist/*",
Expand Down
48 changes: 24 additions & 24 deletions src/components/PsAccounts.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Once integrated, the component can show different cases:
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -94,8 +94,8 @@ If the shop is in a multi-store context, the user will have a selector like this
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: null,
shops: [
{
Expand Down Expand Up @@ -139,8 +139,8 @@ If the shop is in a multi-store context, the user will have a selector like this
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -200,8 +200,8 @@ his address from the link received in his mailbox.
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -266,8 +266,8 @@ You can have these different cases when the shop prerequisites are not fully val
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: false,
psAccountsIsEnabled: true,
psAccountsInstallLink: 'http://localhost:8082/admin-dev/index.php/improve/modules/manage/action/install/ps_accounts?_token=dCspOkG6tWwGoJIKdugKufBFtdNF--UPq8NVmyiUKLM',
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -321,8 +321,8 @@ You can have these different cases when the shop prerequisites are not fully val
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: false,
psAccountsInstallLink: null,
psAccountsEnableLink: 'http://localhost:8082/admin-dev/index.php/improve/modules/manage/action/enable/ps_accounts?_token=dCspOkG6tWwGoJIKdugKufBFtdNF--UPq8NVmyiUKLM',
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -376,8 +376,8 @@ You can have these different cases when the shop prerequisites are not fully val
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -438,8 +438,8 @@ component and the standard behavior won't let the user do anything:
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: 'true', // will pass: can be casted to boolean by Joi
psAccountsIsEnabled: 'ptet-ben-k-non',
psAccountsInstallLink: 'true', // will pass: can be casted to uri by Joi
psAccountsEnableLink: 'ptet-ben-k-non', // will pass: can be casted to uri by Joi
currentShop: 42,
shops: [
{
Expand Down Expand Up @@ -525,8 +525,8 @@ Case with a free plan, with possibility to upgrade to paying plans:
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -610,8 +610,8 @@ Case with paying plan, with possibility to upgrade to more expensive plans:
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -696,8 +696,8 @@ Case with paying plan, without possibility to upgrade to more expensive plan:
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down Expand Up @@ -782,8 +782,8 @@ Display when texts are too long:
context: {
default: object('context', {
psIs17: true,
psAccountsIsInstalled: true,
psAccountsIsEnabled: true,
psAccountsInstallLink: null,
psAccountsEnableLink: null,
currentShop: {
id: 1,
name: 'PrestaShop',
Expand Down
16 changes: 11 additions & 5 deletions src/components/PsAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

<template v-else-if="!showPlans || !canShowPlans">
<AccountNotInstalled
v-if="!validatedContext.psAccountsIsInstalled"
:account-is-installed="validatedContext.psAccountsIsInstalled"
v-if="!psAccountsIsInstalled"
:account-is-installed="psAccountsIsInstalled"
:is-loading="installLoading"
@install="installPsAccounts()"
/>
<template v-else>
<AccountNotEnabled
v-if="!validatedContext.psAccountsIsEnabled"
:account-is-enabled="validatedContext.psAccountsIsEnabled"
v-if="!psAccountsIsEnabled"
:account-is-enabled="psAccountsIsEnabled"
:is-loading="enableLoading"
@enabled="enablePsAccounts()"
/>
Expand Down Expand Up @@ -138,6 +138,12 @@
return this.validatedContext.user.email !== null
&& this.validatedContext.user.emailIsValidated;
},
psAccountsIsInstalled() {
return this.validatedContext.psAccountsInstallLink === null;
},
psAccountsIsEnabled() {
return this.validatedContext.psAccountsEnableLink === null;
},
showBilling() {
const b = this.validatedContext.billing;
const u = this.validatedContext.user;
Expand Down Expand Up @@ -213,7 +219,7 @@
throw new Error('Cannot enable ps_accounts module.');
}
this.validatedContext.psAccountsIsEnabled = true;
this.validatedContext.psAccountsEnableLink = null;
this.enableLoading = false;
}).catch(() => {
this.enableLoading = false;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/ContextValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export const contextSchema = Joi.object().keys({
psIs17: Joi.boolean().required(),
psAccountsInstallLink: Joi.string().uri().allow(null).default(null),
psAccountsEnableLink: Joi.string().uri().allow(null).default(null),
psAccountsIsInstalled: Joi.boolean().required(),
psAccountsIsEnabled: Joi.boolean().required(),
currentShop: shopSchema.optional().allow(null).default(null),
shops: Joi.array().items(shopGroupSchema).required().min(0)
.max(128),
Expand Down

0 comments on commit 0046bd3

Please sign in to comment.