added more option for sorting contact list - projectId
This commit is contained in:
parent
08ace9b5ba
commit
0eaea6a232
@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
import { DirectoryRepository } from "../repositories/DirectoryRepository";
|
||||
import { cacheData, getCachedData } from "../slices/apiDataManager";
|
||||
|
||||
export const useDirectory = (isActive) => {
|
||||
export const useDirectory = (isActive,prefernceContacts) => {
|
||||
const [contacts, setContacts] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
@ -10,7 +10,7 @@ export const useDirectory = (isActive) => {
|
||||
const fetch = async (activeParam = isActive) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await DirectoryRepository.GetContacts(activeParam);
|
||||
const response = await DirectoryRepository.GetContacts(activeParam,prefernceContacts);
|
||||
setContacts(response.data);
|
||||
cacheData("contacts", { data: response.data, isActive: activeParam });
|
||||
} catch (error) {
|
||||
@ -22,12 +22,12 @@ export const useDirectory = (isActive) => {
|
||||
|
||||
useEffect(() => {
|
||||
const cachedContacts = getCachedData("contacts");
|
||||
if (!cachedContacts?.data || cachedContacts.isActive !== isActive) {
|
||||
fetch(isActive);
|
||||
if (!cachedContacts?.data || cachedContacts.isActive !== isActive || prefernceContacts) {
|
||||
fetch(isActive,prefernceContacts);
|
||||
} else {
|
||||
setContacts(cachedContacts.data);
|
||||
}
|
||||
}, [isActive]);
|
||||
}, [isActive,prefernceContacts]);
|
||||
|
||||
return {
|
||||
contacts,
|
||||
|
@ -3,7 +3,17 @@ import {api} from "../utils/axiosClient";
|
||||
export const DirectoryRepository = {
|
||||
GetOrganizations:()=>api.get('/api/directory/organization'),
|
||||
|
||||
GetContacts: (isActive) => api.get( `/api/directory?active=${isActive}` ),
|
||||
GetContacts: (isActive, projectId) => {
|
||||
const params = new URLSearchParams();
|
||||
params.append("active", isActive);
|
||||
|
||||
if (projectId) {
|
||||
params.append("projectId", projectId);
|
||||
}
|
||||
|
||||
return api.get(`/api/Directory?${params.toString()}`);
|
||||
}
|
||||
,
|
||||
CreateContact: ( data ) => api.post( '/api/directory', data ),
|
||||
UpdateContact: ( id, data ) => api.put( `/api/directory/${ id }`, data ),
|
||||
DeleteContact: ( id,isActive) => api.delete( `/api/directory/${ id }/?active=${isActive}` ),
|
||||
|
Loading…
x
Reference in New Issue
Block a user