diff --git a/package-lock.json b/package-lock.json index 90f04fa..afe06d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "axios": "^1.3.4", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-hook-form": "^7.43.9", "react-router-dom": "^6.9.0", "react-scripts": "5.0.1", "sass": "^1.59.3", @@ -14537,6 +14538,21 @@ "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz", "integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==" }, + "node_modules/react-hook-form": { + "version": "7.43.9", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.43.9.tgz", + "integrity": "sha512-AUDN3Pz2NSeoxQ7Hs6OhQhDr6gtF9YRuutGDwPQqhSUAHJSgGl2VeY3qN19MG0SucpjgDiuMJ4iC5T5uB+eaNQ==", + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/react-hook-form" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", @@ -27725,6 +27741,12 @@ "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz", "integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==" }, + "react-hook-form": { + "version": "7.43.9", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.43.9.tgz", + "integrity": "sha512-AUDN3Pz2NSeoxQ7Hs6OhQhDr6gtF9YRuutGDwPQqhSUAHJSgGl2VeY3qN19MG0SucpjgDiuMJ4iC5T5uB+eaNQ==", + "requires": {} + }, "react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", diff --git a/package.json b/package.json index f48e4d5..14d9b0e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "axios": "^1.3.4", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-hook-form": "^7.43.9", "react-router-dom": "^6.9.0", "react-scripts": "5.0.1", "sass": "^1.59.3", diff --git a/src/components/card/card.scss b/src/components/card/card.scss index e9794e3..18f0c1b 100644 --- a/src/components/card/card.scss +++ b/src/components/card/card.scss @@ -116,16 +116,16 @@ top: 24px; background: #e7e9fe; background: $accent2-color; - color: $accent3-color; + color: $text-color-light; padding: 8px 16px; } -.topLeft { +.top-left { border-top-right-radius: 5px; border-bottom-right-radius: 5px; } -.topRight { +.top-right { right: 0; border-top-left-radius: 5px; border-bottom-left-radius: 5px; diff --git a/src/components/card/card.tsx b/src/components/card/card.tsx index 65d21fe..52b77e3 100644 --- a/src/components/card/card.tsx +++ b/src/components/card/card.tsx @@ -1,31 +1,30 @@ -import React, { Component } from 'react'; +import React from 'react'; import './card.scss'; import { IProduct } from '../types'; type CardProps = { product: IProduct }; -type CardState = {}; -export default class Card extends Component { - render() { - const { product } = this.props; - const { title, brand, images, price } = product; +const Card = (props: CardProps) => { + const { product } = props; + const { title, brand, images, price } = product; - return ( -
-
- image + return ( +
+
+ image +
+
+
+

{title}

+
{price}$
+ {brand} +
-
-
-

{title}

-
{price}$
- {brand} - -
-
- Top -
- ); - } -} +
+ Top +
+ ); +}; + +export default Card; diff --git a/src/components/cardForm-list/cardForm-list.tsx b/src/components/cardForm-list/cardForm-list.tsx index 2797e17..99d21ee 100644 --- a/src/components/cardForm-list/cardForm-list.tsx +++ b/src/components/cardForm-list/cardForm-list.tsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { FC } from 'react'; import { ICardForm } from '../cardForm/cardForm'; import CardForm from '../cardForm'; @@ -8,24 +8,23 @@ import './cardForm-list.scss'; type CardFormListProps = { cardsForm: ICardForm[]; }; -type CardFormListState = {}; -export default class CardFormList extends Component { - render() { - const cards = this.props.cardsForm.map((card) => { - const { id } = card; - - return ( -
  • - -
  • - ); - }); +const CardFormList: FC = (props: CardFormListProps) => { + const cards = props.cardsForm.map((card) => { + const { id } = card; return ( -
      - {cards} -
    +
  • + +
  • ); - } -} + }); + + return ( +
      + {cards} +
    + ); +}; + +export default CardFormList; diff --git a/src/components/cardForm/cardForm.tsx b/src/components/cardForm/cardForm.tsx index f13534a..4fca094 100644 --- a/src/components/cardForm/cardForm.tsx +++ b/src/components/cardForm/cardForm.tsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { FC } from 'react'; import './cardForm.scss'; @@ -14,40 +14,39 @@ export interface ICardForm { } type CardFormProps = { card: ICardForm }; -type CardFormState = {}; - -export default class CardForm extends Component { - render() { - const { card } = this.props; - const { userName, gender, birthday, country, isConsentPersonalData, feedbackText, imageSrc } = card; - - return ( -
    -
    -
    - image profile -
    -
    -
    -
    {userName}
    -
    {country}
    -
    -
    -
    - Birthday: - {birthday} -
    -
    {gender}
    -
    +const CardForm: FC = (props: CardFormProps) => { + const { card } = props; + const { userName, gender, birthday, country, isConsentPersonalData, feedbackText, imageSrc } = card; -
    -

    {feedbackText}

    + return ( +
    +
    +
    + image profile
    -
    - Do you consent to my personal data? {isConsentPersonalData ? 'Yes' : 'No'} +
    +
    +
    {userName}
    +
    {country}
    +
    + +
    +
    + Birthday: + {birthday}
    +
    {gender}
    - ); - } -} + +
    +

    {feedbackText}

    +
    +
    + Do you consent to my personal data? {isConsentPersonalData ? 'Yes' : 'No'} +
    +
    + ); +}; + +export default CardForm; diff --git a/src/components/cards-list/cards-list.tsx b/src/components/cards-list/cards-list.tsx index d74bbc5..2ede2f0 100644 --- a/src/components/cards-list/cards-list.tsx +++ b/src/components/cards-list/cards-list.tsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React from 'react'; import './cards-list.scss'; @@ -8,10 +8,9 @@ import { IProduct } from '../types'; type CardListProps = { products: IProduct[]; }; -type CardListState = {}; -export default class CardList extends Component { - cards = this.props.products.slice(0, 8).map((product) => { +const CardList = ({ products }: CardListProps) => { + const cards = products.map((product) => { const { id } = product; return ( @@ -21,11 +20,11 @@ export default class CardList extends Component { ); }); - render() { - return ( -
      - {this.cards} -
    - ); - } -} + return ( +
      + {cards} +
    + ); +}; + +export default CardList; diff --git a/src/components/footer/footer.test.tsx b/src/components/footer/footer.test.tsx new file mode 100644 index 0000000..07e1643 --- /dev/null +++ b/src/components/footer/footer.test.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; + +import Footer from './footer'; + +describe('test Header component', () => { + test('it renders', () => { + render(