Skip to content

Commit

Permalink
Merge pull request #407 from Studio-Yandex-Practicum/enhancement-365-…
Browse files Browse the repository at this point in the history
…create-SubscriptionPage

#365-enhancement-create-SubscriptionPage
  • Loading branch information
aimenin authored Jun 25, 2024
2 parents 70d97c2 + ca4ac1e commit f5ad827
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/app/router/AppRouter/ui/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ProductsPage } from '@/pages/ProductsPage/ProductsPage'
import { ReviewsPage } from '@/pages/ReviewsPage/ReviewsPage'
import RootPage from '@/pages/RootPage/RootPage'
import SearchResultsPage from '@/pages/SearchResultsPage/SearchResultsPage'
import SubscriptionPage from '@/pages/SubscriptionPage/SubscriptionPage'
import ShopNewsPage from '@/pages/ShopNewsPage/ShopNewsPage'

Check failure on line 27 in src/app/router/AppRouter/ui/AppRouter.tsx

View workflow job for this annotation

GitHub Actions / pipeline (18.x)

`@/pages/ShopNewsPage/ShopNewsPage` import should occur before import of `@/pages/SubscriptionPage/SubscriptionPage`
import { TermsPage } from '@/pages/TermsPage/TermsPage'
import VouchersPage from '@/pages/VouchersPage/VouchersPage'
Expand Down Expand Up @@ -144,6 +145,10 @@ export const AppRouter = createBrowserRouter([
path: Routes.REGISTRATION,
element: <CreateAccountPage />
},
{
path: Routes.NEWSLETTER,
element: <SubscriptionPage />
},
{
path: Routes.SUBSCRIBE,
element: <CreateAccountPage /> //TODO реалзиовать страницу подписки
Expand Down
22 changes: 22 additions & 0 deletions src/pages/SubscriptionPage/SubscriptionPage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@use '@/shared/styles/utils/mixins' as media;

.info {
display:flex;
margin-top: 20px;
column-gap: 20px;

@include media.respond-to('large') {
flex-direction: column;
row-gap: 10px;
}
}

.container {
display: flex;
flex-direction: column;
width: 100%;
}

.heading {
margin-bottom: 10px;
}
70 changes: 70 additions & 0 deletions src/pages/SubscriptionPage/SubscriptionPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Suspense, useState } from 'react'

import SideBarMenuModal from '@/features/SideBarMenuModal'
import { useResize } from '@/shared/libs/hooks/useResize'
import Breadcrumbs from '@/shared/ui/Breadcrumbs/Breadcrumbs'
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading'
import Modal from '@/shared/ui/Modal/Modal'
import Spinner from '@/shared/ui/Spinner/Spinner'
import DistributionForm from '@/widgets/DistributionForm/ui/DistributionForm'
import { withAdaptiveSideBar } from '@/widgets/SideBarMenu'

import WrapperForMainContent from '../../components/WrapperForMainContent/WrapperForMainContent'

import styles from './SubscriptionPage.module.scss'

const links = [
{ heading: 'Главная', href: '/' },
{ heading: 'Личный Кабинет', href: '/account' },
{ heading: 'Рассылка', href: '' }
]

const SubscriptionPage = () => {
const [isModalOpen, setIsModalOpen] = useState<boolean>(false)
const [isModalClosing, setIsModalClosing] = useState<boolean>(false)
const { isScreenLg } = useResize()
const AdaptiveSideBar = withAdaptiveSideBar(isScreenLg)

const changeModalState = () => {
setIsModalOpen(!isModalOpen)
}

const handleClick = () => {
setIsModalOpen(true)
}

const closeModal = () => {
setIsModalClosing(true)
}

return (
<>
{isModalOpen && (
<Modal
isModalOpen={isModalOpen}
onClose={changeModalState}
isModalClosing={isModalClosing}
setIsModalClosing={setIsModalClosing}>
<Suspense fallback={<Spinner />}>
<SideBarMenuModal handleClose={closeModal} />
</Suspense>
</Modal>
)}

<WrapperForMainContent>
<div className={styles.container}>
<Heading type={HeadingType.MEDIUM} className={styles.heading}>
Подписка на новости
</Heading>
<Breadcrumbs links={links}></Breadcrumbs>
<div className={styles.info}>
<AdaptiveSideBar handleClick={handleClick} />
<DistributionForm></DistributionForm>
</div>
</div>
</WrapperForMainContent>
</>
)
}

export default SubscriptionPage
1 change: 1 addition & 0 deletions src/shared/config/routerConfig/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum Routes {
FORGOT_PASSWORD = '/forgot-password',
REGISTRATION = '/registration',
SUBSCRIBE = '/subscribe',
NEWSLETTER = '/newsletter',
ERROR = '*',
SHOP_NEWS = '/shopnews'
}
2 changes: 1 addition & 1 deletion src/widgets/AccountSubscribe/AccountSubscribe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import styles from './AccountSubscribe.module.scss'
export const AccountSubscribe: FC = () => {
return (
<section className={styles.accountSubscribe}>
<Link to={Routes.SUBSCRIBE} className={styles.accountSubscribe__content}>
<Link to={Routes.NEWSLETTER} className={styles.accountSubscribe__content}>
<div>
<IconEnvelop className={styles.accountSubscribe__icon} />
<Paragraph className={styles.accountSubscribe__title}>Подписка</Paragraph>
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/DistributionForm/modal/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IDistributionForm {
subscription: string
}
39 changes: 39 additions & 0 deletions src/widgets/DistributionForm/ui/DistributionForm.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@use '@/shared/styles/utils/variables' as var;
@use '@/shared/styles/utils/mixins' as media;

.form {
display: flex;
flex-direction: column;
width: 100%;
padding: 20px 30px;
background: var.$white;
border-radius: 10px;
height: 230px;

@include media.respond-to('small') {
height: 290px;
}

&__title {
margin-bottom: 10px;
}

&__list {
display: flex;
column-gap: 20px;
margin-bottom: 30px;
}

&__buttons {
display: flex;
column-gap: 20px;
flex-direction: row;
width: 70%;

@include media.respond-to('small') {
flex-direction: column;
row-gap: 10px;
}
}
}

17 changes: 17 additions & 0 deletions src/widgets/DistributionForm/ui/DistributionForm.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Meta, StoryObj } from '@storybook/react'

import DistributionForm from './DistributionForm'

const meta = {
title: 'widgets/DistributionForm',
component: DistributionForm,
parameters: {
layout: 'centered'
},
tags: ['autodocs']
} satisfies Meta<typeof DistributionForm>

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {}
87 changes: 87 additions & 0 deletions src/widgets/DistributionForm/ui/DistributionForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Form, Formik } from 'formik'
import { useNavigate } from 'react-router'

import { Routes } from '@/shared/config/routerConfig/routes'
import { Button, ButtonDesign, ButtonSize, ButtonTheme } from '@/shared/ui/Button/Button'
import Checkbox from '@/shared/ui/Checkbox/Checkbox'
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading'
import Label from '@/shared/ui/Label/Label'

import { IDistributionForm } from '../modal/types'

import styles from './DistributionForm.module.scss'

const initialValues: IDistributionForm = {
subscription: String('Нет')
}

const subscription = [
{ label: 'Да', value: 'Да' },
{ label: 'Нет', value: 'Нет' }
]

const DistributionForm = () => {
const navigate = useNavigate()
function handleRedirectPrevious() {
navigate(Routes.ACCOUNT)
}
function handleRedirectNext() {
navigate(Routes.ACCOUNT)
}

return (
<Formik
initialValues={initialValues}
onSubmit={(values, { setSubmitting, resetForm }) => {
setSubmitting(false)
resetForm()
}}>
{({ isSubmitting }) => (
<Form className={styles.form}>
<Heading type={HeadingType.NORMAL} className={styles.form__title}>
Рассылка
</Heading>
<Label htmlFor="subscription" className={`${styles.form__label}`}>
Подписаться
<ul className={styles.form__list}>
{subscription.map(option => {
return (
<li key={option.value}>
<Checkbox
className={styles.form__radio}
htmlFor="subscription"
label={option.label}
name="subscription"
value={option.value}
/>
</li>
)
})}
</ul>
</Label>
<div className={styles.form__buttons}>
<Button
theme={ButtonTheme.PREVIOUS}
design={ButtonDesign.SQUARE}
size={ButtonSize.S}
type="submit"
onClick={handleRedirectPrevious}
disabled={isSubmitting}>
Назад
</Button>
<Button
theme={ButtonTheme.PRIMARY}
design={ButtonDesign.SQUARE}
size={ButtonSize.S}
type="submit"
onClick={handleRedirectNext}
disabled={isSubmitting}>
Продолжить
</Button>
</div>
</Form>
)}
</Formik>
)
}
export default DistributionForm

0 comments on commit f5ad827

Please sign in to comment.