From 82abe0a746fb3e308254c206a3af1b1b44c24b62 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 6 Jul 2020 19:29:56 +0300 Subject: [PATCH] Extract general popups markup to its own component Split popups controllers into separate components Implemented storybooks for all project's popups --- .env.tpl | 2 +- packages/app/components/auth/actions.ts | 2 +- .../components/contact/ContactForm.test.tsx | 32 ++- .../app/components/contact/ContactForm.tsx | 233 +++--------------- .../contact/ContactFormPopup.story.tsx | 16 ++ .../contact/ContactFormPopup.test.tsx | 146 +++++++++++ .../components/contact/ContactFormPopup.tsx | 129 ++++++++++ .../app/components/contact/ContactLink.tsx | 2 +- .../contact/SuccessContactFormPopup.story.tsx | 9 + .../contact/SuccessContactFormPopup.tsx | 38 +++ .../app/components/contact/contactForm.scss | 21 +- packages/app/components/contact/index.ts | 1 + .../languageSwitcher/LanguageSwitcher.tsx | 202 +++------------ .../LanguageSwitcherPopup.story.tsx | 76 ++++++ .../LanguageSwitcherPopup.tsx | 114 +++++++++ .../{LanguageList.tsx => LanguagesList.tsx} | 29 ++- .../languageSwitcher/LocaleItem.tsx | 2 +- .../languageSwitcher/languageSwitcher.scss | 9 +- .../PasswordRequestForm.story.tsx | 17 ++ .../PasswordRequestForm.tsx | 63 +++-- .../profile/passwordRequestForm/index.ts | 1 + .../passwordRequestForm.scss | 5 +- packages/app/components/ui/form/Form.tsx | 6 +- packages/app/components/ui/popup/Popup.tsx | 37 +++ .../components/ui/popup/PopupStack.test.tsx | 6 +- .../app/components/ui/popup/PopupStack.tsx | 20 +- packages/app/components/ui/popup/index.ts | 2 + packages/app/components/ui/popup/popup.scss | 32 ++- packages/app/package.json | 3 +- packages/app/pages/profile/ProfilePage.tsx | 3 +- packages/app/pages/root/RootPage.tsx | 2 +- packages/app/services/api/feedback.ts | 20 +- packages/app/shell/App.tsx | 13 +- packages/app/shell/ContextProvider.tsx | 28 ++- packages/app/shell/TestContextProvider.tsx | 22 +- packages/app/storeFactory.ts | 8 +- .../profile/feedback-popup.test.ts | 2 +- .../cypress/integration/profile/i18n.test.ts | 10 +- yarn.lock | 5 + 39 files changed, 834 insertions(+), 534 deletions(-) create mode 100644 packages/app/components/contact/ContactFormPopup.story.tsx create mode 100644 packages/app/components/contact/ContactFormPopup.test.tsx create mode 100644 packages/app/components/contact/ContactFormPopup.tsx create mode 100644 packages/app/components/contact/SuccessContactFormPopup.story.tsx create mode 100644 packages/app/components/contact/SuccessContactFormPopup.tsx create mode 100644 packages/app/components/languageSwitcher/LanguageSwitcherPopup.story.tsx create mode 100644 packages/app/components/languageSwitcher/LanguageSwitcherPopup.tsx rename packages/app/components/languageSwitcher/{LanguageList.tsx => LanguagesList.tsx} (87%) create mode 100644 packages/app/components/profile/passwordRequestForm/PasswordRequestForm.story.tsx create mode 100644 packages/app/components/profile/passwordRequestForm/index.ts create mode 100644 packages/app/components/ui/popup/Popup.tsx create mode 100644 packages/app/components/ui/popup/index.ts diff --git a/.env.tpl b/.env.tpl index b4e11dd..76b73d2 100644 --- a/.env.tpl +++ b/.env.tpl @@ -1,4 +1,4 @@ -SENTRY_DSN=https://@sentry.io/ +SENTRY_DSN= CROWDIN_API_KEY=abc diff --git a/packages/app/components/auth/actions.ts b/packages/app/components/auth/actions.ts index a2ae2c5..339133d 100644 --- a/packages/app/components/auth/actions.ts +++ b/packages/app/components/auth/actions.ts @@ -21,7 +21,7 @@ import { } from 'app/services/api/signup'; import dispatchBsod from 'app/components/ui/bsod/dispatchBsod'; import { create as createPopup } from 'app/components/ui/popup/actions'; -import ContactForm from 'app/components/contact/ContactForm'; +import ContactForm from 'app/components/contact'; import { Account } from 'app/components/accounts/reducer'; import { ThunkAction, Dispatch } from 'app/reducers'; import { Resp } from 'app/services/request'; diff --git a/packages/app/components/contact/ContactForm.test.tsx b/packages/app/components/contact/ContactForm.test.tsx index 6fe4ebe..cdab5d2 100644 --- a/packages/app/components/contact/ContactForm.test.tsx +++ b/packages/app/components/contact/ContactForm.test.tsx @@ -2,11 +2,11 @@ import React from 'react'; import expect from 'app/test/unexpected'; import sinon from 'sinon'; import { render, fireEvent, waitFor, screen } from '@testing-library/react'; -import feedback from 'app/services/api/feedback'; +import * as feedback from 'app/services/api/feedback'; import { User } from 'app/components/user'; import { TestContextProvider } from 'app/shell'; -import { ContactForm } from './ContactForm'; +import ContactForm from './ContactForm'; beforeEach(() => { sinon.stub(feedback, 'send').returns(Promise.resolve() as any); @@ -18,11 +18,9 @@ afterEach(() => { describe('ContactForm', () => { it('should contain Form', () => { - const user = {} as User; - render( - + , ); @@ -49,14 +47,14 @@ describe('ContactForm', () => { }); describe('when rendered with user', () => { - const user = { + const user: Pick = { email: 'foo@bar.com', - } as User; + }; it('should render email field with user email', () => { render( - - + + , ); @@ -65,13 +63,13 @@ describe('ContactForm', () => { }); it('should submit and then hide form and display success message', async () => { - const user = { + const user: Pick = { email: 'foo@bar.com', - } as User; + }; render( - - + + , ); @@ -113,9 +111,9 @@ describe('ContactForm', () => { }); it('should show validation messages', async () => { - const user = { + const user: Pick = { email: 'foo@bar.com', - } as User; + }; (feedback.send as any).callsFake(() => Promise.reject({ @@ -125,8 +123,8 @@ describe('ContactForm', () => { ); render( - - + + , ); diff --git a/packages/app/components/contact/ContactForm.tsx b/packages/app/components/contact/ContactForm.tsx index 0fff30d..938b764 100644 --- a/packages/app/components/contact/ContactForm.tsx +++ b/packages/app/components/contact/ContactForm.tsx @@ -1,202 +1,43 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import clsx from 'clsx'; -import { FormattedMessage as Message, defineMessages } from 'react-intl'; -import { Input, TextArea, Button, Form, FormModel, Dropdown } from 'app/components/ui/form'; -import feedback from 'app/services/api/feedback'; -import icons from 'app/components/ui/icons.scss'; -import popupStyles from 'app/components/ui/popup/popup.scss'; +import React, { ComponentType, useCallback, useRef, useState } from 'react'; +import { useSelector } from 'react-redux'; + +import { send as sendFeedback } from 'app/services/api/feedback'; import { RootState } from 'app/reducers'; import logger from 'app/services/logger'; -import { User } from 'app/components/user'; -import styles from './contactForm.scss'; +import ContactFormPopup from './ContactFormPopup'; +import SuccessContactFormPopup from './SuccessContactFormPopup'; -const CONTACT_CATEGORIES = { - // TODO: сюда позже проставить реальные id категорий с backend - 0: , - 1: , - 2: , - 3: , - 4: , -}; - -const labels = defineMessages({ - subject: 'Subject', - email: 'E‑mail', - message: 'Message', - whichQuestion: 'What are you interested in?', - - send: 'Send', - - close: 'Close', -}); - -export class ContactForm extends React.Component< - { - onClose: () => void; - user: User; - }, - { - isLoading: boolean; - isSuccessfullySent: boolean; - lastEmail: string | null; - } -> { - static defaultProps = { - onClose() {}, - }; - - state = { - isLoading: false, - isSuccessfullySent: false, - lastEmail: null, - }; - - form = new FormModel(); - - render() { - const { isSuccessfullySent } = this.state || {}; - const { onClose } = this.props; - - return ( -
-
-
-

- -

- -
- - {isSuccessfullySent ? this.renderSuccess() : this.renderForm()} -
-
- ); - } - - renderForm() { - const { form } = this; - const { user } = this.props; - const { isLoading } = this.state; - - return ( -
-
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
- -
- -