From a9825bc8f89c3d39290748df128bcb44b71d5b59 Mon Sep 17 00:00:00 2001 From: Andrii Kuz Date: Mon, 21 Aug 2023 16:59:16 +0300 Subject: [PATCH 1/4] Solved task --- README.md | 2 +- src/App.jsx | 20 ++++---------------- src/components/Person/Person.jsx | 31 ++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3424ccb86..11a09bf5a 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ and use it 3 times inside the `App` instead of static markup. ## Instructions - Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline). - Open one more terminal and run tests with `npm test` to ensure your solution is correct. -- Replace `` with your Github username in the [DEMO LINK](https://.github.io/react_person/) and add it to the PR description. +- Replace `` with your Github username in the [DEMO LINK](https://AndriiKuz.github.io/react_person/) and add it to the PR description. diff --git a/src/App.jsx b/src/App.jsx index dcf8509c8..eb6735128 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import { Person } from './components/Person/Person'; import './App.scss'; export const misha = { @@ -25,21 +26,8 @@ export const alex = { export const App = () => (
-
-

My name is Misha

-

I am 37

-

Natasha is my wife

-
- -
-

My name is Olya

-

Maksym is my husband

-
- -
-

My name is Alex

-

I am 25

-

I am not married

-
+ + +
); diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index eccf156a3..4c5591e75 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1 +1,30 @@ -// export const Person = ({ person }) => (); +export const Person = ({ person }) => { + const { name, age, partnerName, sex, isMarried } = person; + const MALE = 'm'; + + return ( +
+

+ { `My name is ${name}` } +

+ + { + age + ? ( +

+ {`I am ${age}`} +

+ ) + : null + } + +

+ { + isMarried + ? `${partnerName} is my ${sex === MALE ? 'wife' : 'husband'}` + : `I am not married` + } +

+
+ ); +}; From 6852560d62f786745bed79ca35059db16a3543a8 Mon Sep 17 00:00:00 2001 From: Andrii Kuz Date: Wed, 23 Aug 2023 10:27:42 +0300 Subject: [PATCH 2/4] Changed after review --- src/components/Person/Person.jsx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index 4c5591e75..dc5526763 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1,6 +1,14 @@ export const Person = ({ person }) => { - const { name, age, partnerName, sex, isMarried } = person; + const { + name, + age, + partnerName, + sex, + isMarried, + } = person; const MALE = 'm'; + const WIFE = 'wife'; + const HUSBAND = 'husband'; return (
@@ -8,21 +16,12 @@ export const Person = ({ person }) => { { `My name is ${name}` } - { - age - ? ( -

- {`I am ${age}`} -

- ) - : null - } + {age &&

{`I am ${age}`}

}

- { - isMarried - ? `${partnerName} is my ${sex === MALE ? 'wife' : 'husband'}` - : `I am not married` + {isMarried + ? `${partnerName} is my ${sex === MALE ? WIFE : HUSBAND}` + : `I am not married` }

From c4370bc72c3ce96a0bde7a2d015b4eddf024a4d1 Mon Sep 17 00:00:00 2001 From: Andrii Kuz Date: Wed, 23 Aug 2023 15:54:01 +0300 Subject: [PATCH 3/4] Changes after review --- src/components/Person/Person.jsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index dc5526763..6e0fa3efd 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -6,21 +6,28 @@ export const Person = ({ person }) => { sex, isMarried, } = person; + const MALE = 'm'; const WIFE = 'wife'; const HUSBAND = 'husband'; + const partner = sex === MALE ? WIFE : HUSBAND; + return (

{ `My name is ${name}` }

- {age &&

{`I am ${age}`}

} + {Boolean(age) && ( +

+ {`I am ${age}`} +

+ )}

{isMarried - ? `${partnerName} is my ${sex === MALE ? WIFE : HUSBAND}` + ? `${partnerName} is my ${partner}` : `I am not married` }

From b2c84e39ae372473a2446c08ae3e887e1bb0cb22 Mon Sep 17 00:00:00 2001 From: Andrii Kuz Date: Wed, 23 Aug 2023 22:18:32 +0300 Subject: [PATCH 4/4] Changes after review --- src/components/Person/Person.jsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index 6e0fa3efd..5c9b43397 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1,3 +1,7 @@ +const MALE = 'm'; +const WIFE = 'wife'; +const HUSBAND = 'husband'; + export const Person = ({ person }) => { const { name, @@ -7,11 +11,7 @@ export const Person = ({ person }) => { isMarried, } = person; - const MALE = 'm'; - const WIFE = 'wife'; - const HUSBAND = 'husband'; - - const partner = sex === MALE ? WIFE : HUSBAND; + const merriageStatusInfo = sex === MALE ? WIFE : HUSBAND; return (
@@ -27,7 +27,7 @@ export const Person = ({ person }) => {

{isMarried - ? `${partnerName} is my ${partner}` + ? `${partnerName} is my ${merriageStatusInfo}` : `I am not married` }