Skip to content

Commit

Permalink
refactor(Counter): update Counter component to use actionId and fetch…
Browse files Browse the repository at this point in the history
… score dynamically
  • Loading branch information
elisfainstein committed Jan 16, 2025
1 parent 70fcfbf commit 36758d2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const ReferentielCard = ({
const collectiviteId = useCollectiviteId();
const referentiel = referentielId(action.id);

// TODO: remove fake data
const FAKE_pilotes = [
{
nom: 'John Doe',
Expand Down Expand Up @@ -67,17 +68,16 @@ export const ReferentielCard = ({
}}
/>
<div>
<Counter value={1} total={10} className="mb-3" />
<Counter actionId={action.id} className="mb-3" />
<ActionProgressBar
action={action}
className=""
styleOptions={{ justify: 'start', fullWidth: true }}
/>
</div>
</>
) : (
<div>
<Counter value={1} total={10} className="mb-3" />
<Counter actionId={action.id} className="mb-3" />
<ActionProgressBar
action={action}
styleOptions={{ justify: 'start', fullWidth: true }}
Expand Down
16 changes: 11 additions & 5 deletions app.territoiresentransitions.react/src/ui/score/Counter.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Badge } from '@/ui';
import classNames from 'classnames';
import { useActionScore } from '../../core-logic/hooks/scoreHooks';

type CounterProps = {
value: number;
total: number;
actionId: string;
className?: string;
};

export const Counter = ({ value, total, className }: CounterProps) => {
const percentage = (value / total) * 100;
export const Counter = ({ actionId, className }: CounterProps) => {
const score = useActionScore(actionId);

if (!score) return null;

const percentage = Number(
(score.point_fait / score.point_potentiel) * 100
).toFixed(1);

return (
<div className={classNames('flex', className)}>
Expand All @@ -19,7 +25,7 @@ export const Counter = ({ value, total, className }: CounterProps) => {
className="!rounded-r-none border-2 border-r-0"
/>
<Badge
title={value && total ? `${value} / ${total} points` : 'Non renseigné'}
title={`${score.point_fait} / ${score.point_potentiel} points`}
state="success"
light
className="!rounded-l-none border-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ export const ExpandableAction = ({
>
<ActionReferentielDisplayTitle action={action} isOpen={isOpen} />
<div className="flex items-center">
<ActionProgressBar action={action} />
<Counter value={1} total={10} className="ml-28" />
<div className="w-48">
<ActionProgressBar
action={action}
styleOptions={{ fullWidth: true }}
/>
</div>
<div className="w-96">
<Counter actionId={action.id} className="justify-end" />
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 36758d2

Please sign in to comment.