Skip to content

Commit

Permalink
fix : error page commune
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Jan 19, 2024
1 parent c81a203 commit e4d0ebf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
14 changes: 2 additions & 12 deletions components/communes/bals-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ export const BalsItem = (
item: BaseLocaleType,
actions: Record<string, (item: BaseLocaleType) => void>
) => {
const { _id, nom, status, sync, _created, _updated } = item;
const [computedStatus, setComputedStatus] = useState<StatusInterface | null>(
null
);

useEffect(() => {
async function initStatus() {
const habilitationIsValid = await getBaseLocaleIsHabilitationValid(_id);
setComputedStatus(computeStatus(status, sync, habilitationIsValid));
}
const { _id, nom, status, sync, _created, _updated, habilitationIsValid } = item;

void initStatus();
}, [_id, status, sync]);
const computedStatus = computeStatus(status, sync, habilitationIsValid)

return (
<tr key={_id}>
Expand Down
14 changes: 11 additions & 3 deletions pages/communes/[code].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import {getCommune} from '@/lib/cog'

import {ModalAlert} from '@/components/modal-alerte'
import {getAllRevisionByCommune} from '@/lib/api-depot'
import {searchBasesLocales, removeBaseLocale} from '@/lib/api-mes-adresses'
import {searchBasesLocales, removeBaseLocale, getBaseLocaleIsHabilitationValid} from '@/lib/api-mes-adresses'
import {getRevisionsByCommune} from '@/lib/api-moissonneur-bal'

import {EditableList} from '@/components/editable-list'
import {RevisionItemApiDepot} from '@/components/communes/revisions-item-api-depot'
import {RevisionItemMoissoneur} from '@/components/communes/revisions-item-moissoneur'
import {BalsItem} from '@/components/communes/bals-item'

const getBasesLocalesIsHabilitationValid = async (bals: BaseLocaleType[]) => {
for (const bal of bals) {
bal.habilitationIsValid = await getBaseLocaleIsHabilitationValid(bal._id)
}
}

type CommuneSourcePageProps = {
code: string;
balsPage: PageType<BaseLocaleType>;
Expand All @@ -24,7 +30,7 @@ type CommuneSourcePageProps = {
const CommuneSource = (
{code, balsPage}: CommuneSourcePageProps,
) => {
const [bals, setBals] = useState(balsPage.results)
const [bals, setBals] = useState<BaseLocaleType[]>(balsPage.results)
const [initialRevisionsApiDepot, setInitialRevisionsApiDepot] = useState<RevisionApiDepotType[]>([])
const [initialRevisionsMoissonneur, setInitialRevisionsMoissonneur] = useState<RevisionMoissoneurType[]>([])
const [balToDeleted, setBalToDeleted] = useState(null)
Expand Down Expand Up @@ -61,6 +67,7 @@ const CommuneSource = (

const fetchBals = useCallback(async (commune: string) => {
const res = await searchBasesLocales({commune, page: pageMesAdresses.current, limit: pageMesAdresses.limit})
await getBasesLocalesIsHabilitationValid(res.results)
setBals(res.results)
}, [pageMesAdresses])

Expand Down Expand Up @@ -152,7 +159,8 @@ const CommuneSource = (

export async function getServerSideProps({params}) {
const {code} = params
const balsPage = await searchBasesLocales({commune: code, page: 1, limit: 5})
const balsPage = await searchBasesLocales({commune: code, page: 1, limit: 10})
await getBasesLocalesIsHabilitationValid(balsPage.results)
return {props: {code, balsPage}}
}

Expand Down
1 change: 1 addition & 0 deletions types/mes-adresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export type BaseLocaleType = {
_created?: string;
_updated?: string;
_deleted?: string;
habilitationIsValid?: boolean;
}

0 comments on commit e4d0ebf

Please sign in to comment.