From 0b9385a983015b4765fee4e78aa82162160425ec Mon Sep 17 00:00:00 2001 From: Julia Qiu Date: Sun, 5 Jul 2020 14:37:31 -0700 Subject: [PATCH] add a feature flag for payments --- .env.example | 1 + next.config.js | 1 + src/components/NDA/NDAComposer.js | 36 ++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index dbff179..b88a11d 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ LINKEDIN_CLIENT_ID= LINKEDIN_CLIENT_SCOPES="r_liteprofile r_emailaddress" NDAIFY_ENDPOINT_URL=http://localhost:8080 NDAIFY_LOG_LEVEL=info +NDAIFY_SOLICIT_PAYMENTS=on NODE_ENV=development SENTRY_DSN=https://@.ingest.sentry.io/id SENTRY_SECRET_TOKEN= diff --git a/next.config.js b/next.config.js index b4b3333..acb5cd9 100644 --- a/next.config.js +++ b/next.config.js @@ -26,6 +26,7 @@ module.exports = () => withSourceMaps(withCSS(withImages({ LINKEDIN_CLIENT_SCOPES: process.env.LINKEDIN_CLIENT_SCOPES, NDAIFY_ENDPOINT_URL: process.env.NDAIFY_ENDPOINT_URL, NDAIFY_LOG_LEVEL: process.env.NDAIFY_LOG_LEVEL, + NDAIFY_SOLICIT_PAYMENTS: process.env.NDAIFY_SOLICIT_PAYMENTS, SENTRY_DSN: process.env.SENTRY_DSN, STRIPE_PUBLISHABLE_KEY: process.env.STRIPE_PUBLISHABLE_KEY, }, diff --git a/src/components/NDA/NDAComposer.js b/src/components/NDA/NDAComposer.js index 54b1f3f..74b4fb3 100644 --- a/src/components/NDA/NDAComposer.js +++ b/src/components/NDA/NDAComposer.js @@ -1,5 +1,6 @@ import React, { useCallback, useState } from 'react'; import styled from 'styled-components'; +import getConfig from 'next/config'; import { Formik, @@ -27,6 +28,10 @@ import HideImg from './images/hide.svg'; import getFullNameFromUser from './getFullNameFromUser'; +import NdaifyService from '../../services/NdaifyService'; + +const { publicRuntimeConfig: { NDAIFY_SOLICIT_PAYMENTS } } = getConfig(); + const HideIcon = styled(HideImg)` color: var(--ndaify-fg); `; @@ -296,36 +301,43 @@ const NDAComposer = ({ ndaTemplate, user, nda }) => { // clear all error messages before retrying setStatus(); + const ndaifyService = new NdaifyService(); + if (!expandedBody) { setStatus({ errorMessage: 'Please expand the NDA to read all terms' }); return; } try { - sessionStorage.setItem( - 'nda', - { - ...nda, - metadata: { - ...nda.metadata, - ndaParamaters: { - ...values, - }, + const ndaPayload = { + ...nda, + metadata: { + ...nda.metadata, + ndaParamaters: { + ...values, }, }, - ); + }; + + sessionStorage.setItem('nda', ndaPayload); // Pretend like we are doing some work before moving to next step // This is much better UX than just navigating away from the form await timeout(1000); - Router.replace('/nda/pay').then(scrollToTop); + if (NDAIFY_SOLICIT_PAYMENTS === 'on') { + Router.replace('/nda/pay').then(scrollToTop); + } else { + const response = await ndaifyService.createNda(ndaPayload); + + Router.replace('/nda/sent/[ndaId]', `/nda/sent/${response.nda.ndaId}`).then(scrollToTop); + } } catch (error) { loggerClient.error(error); setStatus({ errorMessage: error.message }); } }; - const onSubmit = useCallback(handleSubmit, [expandedBody]); + const onSubmit = useCallback(handleSubmit, [expandedBody, nda]); const handleFormValidate = (values) => { const errors = {};