-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from NicolasOmar/feature/created-pets-widget
Feature | Create Widget to look created Pets and its composition | Front end
- Loading branch information
Showing
13 changed files
with
125 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"petPopulationWidget": { | ||
"key": "widget-item", | ||
"cardContent": [ | ||
{ | ||
"type": "title", | ||
"content": { | ||
"titleText": "My Pets", | ||
"titleSize": "normal", | ||
"styles": { "marginBottom": "20px" } | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"content": null | ||
} | ||
] | ||
}, | ||
"cardListTitle": { | ||
"titleSize": "bigger", | ||
"subText": "Welcome to our beautiful place", | ||
"subSize": "small", | ||
"isCentered": true, | ||
"childWidth": 12, | ||
"styles": { "margin": "20px 0px" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,80 @@ | ||
import React, { useState } from 'react' | ||
import React, { useState, useEffect } from 'react' | ||
// GRAPHQL CLIENT | ||
import { useLazyQuery } from '@apollo/client' | ||
import { GET_MY_PETS_POPULATION } from '../../../graphql/queries' | ||
// COMPONENTS | ||
import CardsListTemplate from '../../templates/CardsListTemplate' | ||
import TagList from '../../molecules/TagList' | ||
// HELPER FUNCTIONS | ||
import ProgressBar from '../../atoms/ProgressBar' | ||
// FUNCTIONS | ||
import { getLoggedUser } from '../../../functions/local-storage' | ||
// MOCKS | ||
import config from './config.json' | ||
|
||
const { cardListTitle, petPopulationWidget } = config | ||
|
||
const Home = () => { | ||
const [user] = useState(getLoggedUser()) | ||
|
||
const cardsListTitle = { | ||
titleText: `HELLO ${user?.name?.toUpperCase()}`, | ||
titleSize: 'bigger', | ||
subText: 'Welcome to our beautiful place', | ||
subSize: 'small', | ||
isCentered: true, | ||
childWidth: 12, | ||
styles: { margin: '20px 0px' } | ||
} | ||
|
||
const cardListData = [ | ||
const [cardListData, setCardListData] = useState([ | ||
{ | ||
key: `widget-item`, | ||
...petPopulationWidget, | ||
cardContent: [ | ||
petPopulationWidget.cardContent[0], | ||
{ | ||
type: 'title', | ||
content: { | ||
titleText: 'First widget test', | ||
titleSize: 'normal', | ||
styles: { marginBottom: '20px' } | ||
} | ||
}, | ||
{ | ||
type: 'section', | ||
content: ( | ||
<TagList | ||
{...{ | ||
dataList: Array(13) | ||
.fill(null) | ||
.map((_, i) => ({ | ||
text: `widget-test-${++i}`, | ||
color: i % 2 ? 'success' : 'danger' | ||
})) | ||
}} | ||
/> | ||
) | ||
...petPopulationWidget.cardContent[1], | ||
content: <ProgressBar isInfiniteLoading={true} /> | ||
} | ||
] | ||
} | ||
] | ||
]) | ||
const [getData, { data }] = useLazyQuery(GET_MY_PETS_POPULATION) | ||
|
||
useEffect(() => { | ||
const asyncGetData = async () => await getData() | ||
asyncGetData() | ||
}, [getData]) | ||
|
||
useEffect(() => { | ||
if (data) { | ||
const [all, ...pets] = data.getMyPetsPopulation | ||
setCardListData([ | ||
{ | ||
...petPopulationWidget, | ||
cardContent: [ | ||
{ | ||
...petPopulationWidget.cardContent[0], | ||
content: { | ||
...petPopulationWidget.cardContent[0].content, | ||
titleText: `${ | ||
all.quantity === 0 ? `No created Pets yet` : `Created Pets: ${all.quantity}` | ||
}` | ||
} | ||
}, | ||
{ | ||
...petPopulationWidget.cardContent[1], | ||
content: ( | ||
<TagList | ||
{...{ | ||
dataList: pets.map(({ name, quantity }, i) => ({ | ||
text: `${name}s: ${quantity}`, | ||
color: i % 2 ? 'success' : 'danger' | ||
})) | ||
}} | ||
/> | ||
) | ||
} | ||
] | ||
} | ||
]) | ||
} | ||
}, [data]) | ||
|
||
const cardsListTitle = { | ||
...cardListTitle, | ||
titleText: `HELLO ${user?.name?.toUpperCase()}` | ||
} | ||
|
||
return <CardsListTemplate {...{ isFetching: false, cardsListTitle, cardListData }} /> | ||
return <CardsListTemplate {...{ cardsListTitle, cardListData }} /> | ||
} | ||
|
||
export default Home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters