Skip to content
Snippets Groups Projects
Commit c8846de6 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

fix display

parent db3e0d97
No related branches found
No related tags found
1 merge request!26feat(price): Add price managment
Pipeline #21738 passed
import React, { import React, { useCallback, useContext, useEffect, useState } from 'react'
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css' import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'
import { FluidType } from '../../enum/fluidTypes' import { FluidType } from '../../enum/fluidTypes'
import { FrequencyInMonth } from '../../enum/frequency.enum' import { FrequencyInMonth } from '../../enum/frequency.enum'
...@@ -30,6 +24,7 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -30,6 +24,7 @@ const PriceSection: React.FC<PriceSectionProps> = ({
const [isLoading, setIsLoading] = useState<boolean>(false) const [isLoading, setIsLoading] = useState<boolean>(false)
const [refreshData, setRefreshData] = useState(false) const [refreshData, setRefreshData] = useState(false)
const [showHistory, setshowHistory] = useState<boolean>(false) const [showHistory, setshowHistory] = useState<boolean>(false)
const [showFullList, setshowFullList] = useState<boolean>(false)
const [priceToSave, setpriceToSave] = useState<IPrice>({ const [priceToSave, setpriceToSave] = useState<IPrice>({
fluidType: fluid, fluidType: fluid,
price: '', price: '',
...@@ -37,7 +32,8 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -37,7 +32,8 @@ const PriceSection: React.FC<PriceSectionProps> = ({
endDate: null, endDate: null,
}) })
const { user }: Partial<UserContextProps> = useContext(UserContext) const { user }: Partial<UserContextProps> = useContext(UserContext)
const editableLimit = 3 const editableLimit: number = 3
const maxPerList: number = 8
const handlePriceSelection = (val: string) => { const handlePriceSelection = (val: string) => {
if (val === '') val = '0' if (val === '') val = '0'
val = val.replace(/,/g, '.') val = val.replace(/,/g, '.')
...@@ -46,7 +42,12 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -46,7 +42,12 @@ const PriceSection: React.FC<PriceSectionProps> = ({
} }
const savePrice = async () => { const savePrice = async () => {
if (priceToSave && user) { if (
priceToSave &&
user &&
priceToSave.price !== '0' &&
priceToSave.price !== ''
) {
const priceService = new PricesService() const priceService = new PricesService()
const formattedPrice = { const formattedPrice = {
...priceToSave, ...priceToSave,
...@@ -67,6 +68,10 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -67,6 +68,10 @@ const PriceSection: React.FC<PriceSectionProps> = ({
const year = date.toLocaleString('fr', { year: 'numeric' }) const year = date.toLocaleString('fr', { year: 'numeric' })
return `${month} ${year}` return `${month} ${year}`
} }
const toggleFullList = useCallback(() => {
setshowFullList((prev) => !prev)
}, [])
useEffect(() => { useEffect(() => {
let subscribed = true let subscribed = true
setIsLoading(true) setIsLoading(true)
...@@ -98,8 +103,9 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -98,8 +103,9 @@ const PriceSection: React.FC<PriceSectionProps> = ({
return () => { return () => {
subscribed = false subscribed = false
setIsLoading(false)
} }
}, [refreshData]) }, [refreshData, frequency, fluid])
if (isLoading) return <Loader></Loader> if (isLoading) return <Loader></Loader>
return ( return (
...@@ -115,14 +121,16 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -115,14 +121,16 @@ const PriceSection: React.FC<PriceSectionProps> = ({
<div className="flex-bloc"> <div className="flex-bloc">
<p>Nouveau prix : </p> <p>Nouveau prix : </p>
<input <input
className="input-dark" className="input-dark price-select"
type="text" type="text"
value={priceToSave.price.toString()} value={priceToSave.price.toString()}
onChange={(e) => handlePriceSelection(e.target.value)} onChange={(e) => handlePriceSelection(e.target.value)}
placeholder={ placeholder={
priceToSave.price === '' ? 'Saisir le nouveau prix' : '' priceToSave.price === '' ? 'Saisir le nouveau prix' : ''
} }
></input> />
<span className="euro"></span>
<div className="flex-bloc startDate"> <div className="flex-bloc startDate">
<p>A partir de : </p> <p>A partir de : </p>
<p className="date"> <p className="date">
...@@ -132,7 +140,13 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -132,7 +140,13 @@ const PriceSection: React.FC<PriceSectionProps> = ({
</p> </p>
</div> </div>
</div> </div>
<button
className="btnValid"
onClick={savePrice}
disabled={priceToSave.price === '0' || priceToSave.price === ''}
>
Sauvegarder
</button>
<div className="history"> <div className="history">
<button <button
onClick={toggleHistory} onClick={toggleHistory}
...@@ -142,6 +156,7 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -142,6 +156,7 @@ const PriceSection: React.FC<PriceSectionProps> = ({
<img <img
src={arrowDown} src={arrowDown}
className={showHistory ? 'icon-active' : ''} className={showHistory ? 'icon-active' : ''}
alt="arrow-icon"
/> />
</button> </button>
{showHistory && ( {showHistory && (
...@@ -167,6 +182,7 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -167,6 +182,7 @@ const PriceSection: React.FC<PriceSectionProps> = ({
<img <img
src={editing} src={editing}
onClick={() => setpriceToSave(nextPrice)} onClick={() => setpriceToSave(nextPrice)}
alt="edit-icon"
/> />
</li> </li>
<hr></hr> <hr></hr>
...@@ -174,7 +190,12 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -174,7 +190,12 @@ const PriceSection: React.FC<PriceSectionProps> = ({
)} )}
{prices.map((price, i) => { {prices.map((price, i) => {
return ( return (
<div key={i}> <div
key={i}
className={
i > maxPerList && !showFullList ? 'price-hidden' : ''
}
>
<li <li
className={ className={
priceToSave.startDate === price.startDate priceToSave.startDate === price.startDate
...@@ -184,30 +205,36 @@ const PriceSection: React.FC<PriceSectionProps> = ({ ...@@ -184,30 +205,36 @@ const PriceSection: React.FC<PriceSectionProps> = ({
> >
<div className="prix">{price.price}</div> <div className="prix">{price.price}</div>
<p> <p>
{' '}
à partir de :{' '} à partir de :{' '}
<span className="capital"> <span className="capital">
{getDate(price.startDate)} {getDate(price.startDate)}
</span> </span>
</p> </p>
{i < editableLimit && ( {i < editableLimit - 1 && (
<img <img
src={editing} src={editing}
onClick={() => setpriceToSave(prices[i])} onClick={() => setpriceToSave(prices[i])}
alt="edit-icon"
/> />
)} )}
</li> </li>
<hr></hr> <hr></hr>
{i === maxPerList && !showFullList && (
<button onClick={toggleFullList} className="showButton">
En voir plus
</button>
)}
</div> </div>
) )
})} })}
{showFullList && (
<button onClick={toggleFullList} className="showButton">
En voir moins
</button>
)}
</ul> </ul>
)} )}
</div> </div>
<button className="btnValid" onClick={savePrice}>
Sauvegarder
</button>
</> </>
) : ( ) : (
'Aucun prix trouvé' 'Aucun prix trouvé'
......
...@@ -23,6 +23,14 @@ ...@@ -23,6 +23,14 @@
.flex-bloc { .flex-bloc {
display: flex; display: flex;
align-items: center; align-items: center;
.price-select {
position: relative;
}
.euro {
display: block;
margin-left: 0.5rem;
font-weight: bold;
}
.startDate { .startDate {
margin-left: 1rem; margin-left: 1rem;
.date { .date {
...@@ -42,6 +50,10 @@ ...@@ -42,6 +50,10 @@
border: solid 1px $gold; border: solid 1px $gold;
display: flex; display: flex;
align-items: center; align-items: center;
&:hover {
background: $dark-background;
opacity: 0.8;
}
&.active { &.active {
border-radius: 5px 5px 0 0; border-radius: 5px 5px 0 0;
} }
...@@ -58,6 +70,9 @@ ...@@ -58,6 +70,9 @@
background: $grey-dark; background: $grey-dark;
border: solid 1px $gold; border: solid 1px $gold;
padding: 1rem; padding: 1rem;
.price-hidden {
display: none;
}
li { li {
transition: all 300ms ease; transition: all 300ms ease;
margin: 0.5rem 0; margin: 0.5rem 0;
...@@ -91,6 +106,10 @@ ...@@ -91,6 +106,10 @@
margin: 0; margin: 0;
background: white; background: white;
} }
.showButton {
text-align: center;
color: $gold;
}
} }
.icon-active { .icon-active {
transform: rotate(180deg); transform: rotate(180deg);
......
...@@ -46,6 +46,10 @@ $main-spacing: 4px; ...@@ -46,6 +46,10 @@ $main-spacing: 4px;
&:hover { &:hover {
background-color: #b89318; background-color: #b89318;
} }
&:disabled {
opacity: 0.8;
cursor: not-allowed;
}
} }
.btnValid { .btnValid {
@include baseButton(); @include baseButton();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment