-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64b09fd
commit 3fbf244
Showing
3 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,22 +1,26 @@ | ||
import axios from 'axios'; | ||
import React from 'react'; | ||
import { useQuery } from 'react-query'; | ||
import {UserContext} from "../../contexts/userContext"; | ||
import React from "react"; | ||
import {UserType} from "../../../types/user.type"; | ||
const { user } = React.useContext(UserContext); | ||
|
||
import { UserType } from '../../../types/user.type'; | ||
import { UserContext } from '../../contexts/userContext'; | ||
|
||
const BASE_URL = '/api/archives'; | ||
|
||
// Récupérer la liste des années déjà archivées | ||
export const useListArchives = () => { | ||
const { user } = React.useContext(UserContext); | ||
if(!user) return; | ||
const hasAccess = user?.type === [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR].find((type) => type === user?.type); | ||
if (!hasAccess) { | ||
return; | ||
} | ||
return useQuery(['archives'], async () => { | ||
const { data } = await axios.get(`${BASE_URL}`); | ||
return data; | ||
}); | ||
|
||
const hasAccess = user && [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR].includes(user.type); | ||
|
||
return useQuery( | ||
['archives'], | ||
async () => { | ||
const { data } = await axios.get(`${BASE_URL}`); | ||
return data; | ||
}, | ||
{ | ||
enabled: hasAccess, // La requête ne sera exécutée que si hasAccess est true | ||
}, | ||
); | ||
}; |
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