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 { DirectoryRepository } from "../repositories/DirectoryRepository";
|
||||||
import { cacheData, getCachedData } from "../slices/apiDataManager";
|
import { cacheData, getCachedData } from "../slices/apiDataManager";
|
||||||
|
|
||||||
export const useDirectory = (isActive) => {
|
export const useDirectory = (isActive,prefernceContacts) => {
|
||||||
const [contacts, setContacts] = useState([]);
|
const [contacts, setContacts] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
@ -10,7 +10,7 @@ export const useDirectory = (isActive) => {
|
|||||||
const fetch = async (activeParam = isActive) => {
|
const fetch = async (activeParam = isActive) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await DirectoryRepository.GetContacts(activeParam);
|
const response = await DirectoryRepository.GetContacts(activeParam,prefernceContacts);
|
||||||
setContacts(response.data);
|
setContacts(response.data);
|
||||||
cacheData("contacts", { data: response.data, isActive: activeParam });
|
cacheData("contacts", { data: response.data, isActive: activeParam });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -22,12 +22,12 @@ export const useDirectory = (isActive) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const cachedContacts = getCachedData("contacts");
|
const cachedContacts = getCachedData("contacts");
|
||||||
if (!cachedContacts?.data || cachedContacts.isActive !== isActive) {
|
if (!cachedContacts?.data || cachedContacts.isActive !== isActive || prefernceContacts) {
|
||||||
fetch(isActive);
|
fetch(isActive,prefernceContacts);
|
||||||
} else {
|
} else {
|
||||||
setContacts(cachedContacts.data);
|
setContacts(cachedContacts.data);
|
||||||
}
|
}
|
||||||
}, [isActive]);
|
}, [isActive,prefernceContacts]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contacts,
|
contacts,
|
||||||
|
|||||||
@ -3,7 +3,17 @@ import {api} from "../utils/axiosClient";
|
|||||||
export const DirectoryRepository = {
|
export const DirectoryRepository = {
|
||||||
GetOrganizations:()=>api.get('/api/directory/organization'),
|
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 ),
|
CreateContact: ( data ) => api.post( '/api/directory', data ),
|
||||||
UpdateContact: ( id, data ) => api.put( `/api/directory/${ id }`, data ),
|
UpdateContact: ( id, data ) => api.put( `/api/directory/${ id }`, data ),
|
||||||
DeleteContact: ( id,isActive) => api.delete( `/api/directory/${ id }/?active=${isActive}` ),
|
DeleteContact: ( id,isActive) => api.delete( `/api/directory/${ id }/?active=${isActive}` ),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user