Skip to content

Commit

Permalink
Merge pull request #21 from vuestorefront-community/dev
Browse files Browse the repository at this point in the history
chore: release version 1.2.0
  • Loading branch information
odranoelBR authored Feb 18, 2022
2 parents 29270b4 + 08560d0 commit e25b506
Show file tree
Hide file tree
Showing 12 changed files with 653 additions and 93 deletions.
2 changes: 1 addition & 1 deletion packages/api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-storefront/odoo-api",
"version": "1.1.3",
"version": "1.2.0",
"private": false,
"sideEffects": false,
"server": "server/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/api-client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ export { default as paymentLoadProviders } from './paymentLoadProviders';
export { default as paymentMakeExternal } from './paymentMakeExternal';
export { default as paymentConfirmation } from './paymentConfirmation';

export { default as subscribeNewsLetter } from './subscribeNewsLetter';

export { default as ordersGet } from './ordersGet';
26 changes: 26 additions & 0 deletions packages/api-client/src/api/subscribeNewsLetter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import gql from 'graphql-tag';
import { Context, CustomQuery } from '@vue-storefront/core';
import mutation from './subscribeNewsLetterMutation';
import ApolloClient from 'apollo-client';
import { GraphQlAddAddressParams, DefaultGraphQlMutationResponse } from '../../index';
import { FetchResult } from 'apollo-link/lib/types';

export default async function subscribeNewsLetter(
context: Context,
params: GraphQlAddAddressParams,
customQuery?: CustomQuery
): Promise<FetchResult<DefaultGraphQlMutationResponse>> {
const apolloClient = context.client.apollo as ApolloClient<any>;

const { subscribeNewsLetter } = context.extendQuery(
customQuery, { subscribeNewsLetter: { mutation, variables: params } }
);

const response = await apolloClient.mutate({
mutation: gql`${subscribeNewsLetter.mutation}`,
variables: subscribeNewsLetter.variables
});

return response;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import gql from 'graphql-tag';

export default gql`
mutation($email: String){
newsletterSubscribe(email: $email){
subscribed
}
}`;
2 changes: 2 additions & 0 deletions packages/api-client/src/types/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ export interface OdooApiMethods {
paymentMakeExternal(params: GraphQlMakePaymentParams, customQuery?: CustomQuery): Promise<FetchResult<PaymentMakeExternalResult>>;
paymentConfirmation(customQuery?: CustomQuery): Promise<FetchResult>;

subscribeNewsLetter(customQuery?: CustomQuery): Promise<FetchResult>;

ordersGet(params: GraphQlOrdersParams, customQuery?: CustomQuery): Promise<FetchResult<OrdersResponse>>;
}
4 changes: 2 additions & 2 deletions packages/composables/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-storefront/odoo",
"version": "1.1.3",
"version": "1.2.0",
"private": false,
"sideEffects": false,
"main": "lib/index.cjs.js",
Expand All @@ -19,7 +19,7 @@
"dependencies": {
"@nuxtjs/composition-api": "0.31.0",
"@vue-storefront/core": "2.5.4",
"@vue-storefront/odoo-api": "1.1.3"
"@vue-storefront/odoo-api": "1.2.0"
},
"peerDependencies": {
"@vue/composition-api": "1.2.4"
Expand Down
26 changes: 26 additions & 0 deletions packages/composables/src/composables/useNewsLetter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
Context, Logger
} from '@vue-storefront/core';
import useUser from '../useUser';
import { useNewsletterFactory, UseNewsletterFactoryParams } from '../../factories/useNewsLetterFactory';

const factoryParams: UseNewsletterFactoryParams<any, string> = {
provide() {
return {
user: useUser()
};
},
sendSubscription: async (context: Context, params) => {
Logger.debug('[Magento]: Update user newsletter subscription', { params });

const { data } = await context.$odoo.api.subscribeNewsLetter(
{
email: params.email
}
);

return data.newsletterSubscribe;
}
};

export default useNewsletterFactory<any, string>(factoryParams);
65 changes: 65 additions & 0 deletions packages/composables/src/factories/useNewsLetterFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Ref, computed } from '@vue/composition-api';
import {
ComposableFunctionArgs,
configureFactoryParams,
Context,
FactoryParams,
Logger,
sharedRef
} from '@vue-storefront/core';
import { Composable, ComputedProperty, PlatformApi } from '@vue-storefront/core/lib/src/types';

export interface UseNewsletterErrors {
sendSubscription: Error;
}

export interface UseNewsletter<SEND_NEWSLETTER_PARAMS, API extends PlatformApi = any> extends Composable<API> {
error: ComputedProperty<UseNewsletterErrors>;
loading: ComputedProperty<boolean>;
sendSubscription: (params: ComposableFunctionArgs<{ email: SEND_NEWSLETTER_PARAMS }>) => Promise<void>;
}

export interface UseNewsletterFactoryParams<NEWSLETTER, SEND_NEWSLETTER_PARAMS, API extends PlatformApi = any> extends FactoryParams<API> {
sendSubscription: (context: Context, params: ComposableFunctionArgs<{ email: SEND_NEWSLETTER_PARAMS }>) => Promise<NEWSLETTER>;
}

export const useNewsletterFactory = <NEWSLETTER, SEND_NEWSLETTER_PARAMS, API extends PlatformApi = any>(
factoryParams: UseNewsletterFactoryParams<NEWSLETTER, SEND_NEWSLETTER_PARAMS, API>
) => function useNewsletter(): UseNewsletter<SEND_NEWSLETTER_PARAMS, API> {
const errorsFactory = (): UseNewsletterErrors => ({
sendSubscription: null
});

const loading: Ref<boolean> = sharedRef(false, 'useNewsletter-loading');
// eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle
const _factoryParams = configureFactoryParams(factoryParams);
const error: Ref<UseNewsletterErrors> = sharedRef(errorsFactory(), 'useNewsletter-error');

const resetErrorValue = () => {
error.value = errorsFactory();
};

const sendSubscription = async (params: ComposableFunctionArgs<{ email: SEND_NEWSLETTER_PARAMS }>) => {
Logger.debug('useNewsletterFactory.sendSubscription', params);
resetErrorValue();

try {
loading.value = true;
error.value.sendSubscription = null;
console.log(await _factoryParams.sendSubscription(params));

return await _factoryParams.sendSubscription(params);
} catch (err) {
error.value.sendSubscription = err;
Logger.error('useNewsletter/sendSubscription', err);
} finally {
loading.value = false;
}
};

return {
error: computed(() => error.value),
loading: computed(() => loading.value),
sendSubscription
};
};
1 change: 1 addition & 0 deletions packages/composables/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export { default as usePayment } from './composables/usePayment';
export { default as useAdyenExternalPaymentProvider } from './composables/useAdyenExternalPaymentProvider';
export { default as useShippingMethods } from './composables/useShippingMethods';
export { default as useStore } from './composables/useStore';
export { default as useNewsLetter } from './composables/useNewsLetter';

export * from './composables/getters';
4 changes: 2 additions & 2 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-storefront/odoo-theme",
"version": "1.1.3",
"version": "1.2.0",
"private": true,
"scripts": {
"build": "nuxt build -m --dotenv .env_production",
Expand All @@ -25,7 +25,7 @@
"@vue-storefront/middleware": "2.5.4",
"@vue-storefront/nuxt": "2.5.4",
"@vue-storefront/nuxt-theme": "2.5.4",
"@vue-storefront/odoo": "1.1.3",
"@vue-storefront/odoo": "1.2.0",
"cookie-universal-nuxt": "^2.1.3",
"core-js": "^2.6.5",
"nuxt": "2.15.6",
Expand Down
Loading

0 comments on commit e25b506

Please sign in to comment.