* Adding the favorite button * favorites services and resolvers * favorites schema * favorite ability handler * favorite module export * front end UI * front end graphql additions * server ability handlers * server resolvers and services * css fix * Adding the favorite button * favorites services and resolvers * favorites schema * favorite ability handler * favorite module export * front end UI * front end graphql additions * server ability handlers * server resolvers and services * css fix * delete favorites handler and resolver * removed favorite from index list * chip avatar size props * index list additions * UI additions for favorites functionality * lint fixes * graphql codegen * UI fixes * favorite hook addition * moved to ~/modules * Favorite mapping to workspaceMember * graphql codegen * cosmetic changes * camel cased methods * graphql codegen
85 lines
2.0 KiB
TypeScript
85 lines
2.0 KiB
TypeScript
import { getOperationName } from '@apollo/client/utilities';
|
|
|
|
import { GET_COMPANY } from '@/companies/queries';
|
|
import { GET_PERSON } from '@/people/queries/show';
|
|
import {
|
|
useDeleteFavoriteMutation,
|
|
useInsertCompanyFavoriteMutation,
|
|
useInsertPersonFavoriteMutation,
|
|
} from '~/generated/graphql';
|
|
|
|
import { GET_FAVORITES } from '../queries/show';
|
|
|
|
export function useFavorites() {
|
|
const [insertCompanyFavoriteMutation] = useInsertCompanyFavoriteMutation();
|
|
const [insertPersonFavoriteMutation] = useInsertPersonFavoriteMutation();
|
|
const [deleteFavoriteMutation] = useDeleteFavoriteMutation();
|
|
|
|
function insertCompanyFavorite(companyId: string) {
|
|
insertCompanyFavoriteMutation({
|
|
variables: {
|
|
data: {
|
|
companyId,
|
|
},
|
|
},
|
|
refetchQueries: [
|
|
getOperationName(GET_FAVORITES) ?? '',
|
|
getOperationName(GET_COMPANY) ?? '',
|
|
],
|
|
});
|
|
}
|
|
|
|
function insertPersonFavorite(personId: string) {
|
|
insertPersonFavoriteMutation({
|
|
variables: {
|
|
data: {
|
|
personId,
|
|
},
|
|
},
|
|
refetchQueries: [
|
|
getOperationName(GET_FAVORITES) ?? '',
|
|
getOperationName(GET_PERSON) ?? '',
|
|
],
|
|
});
|
|
}
|
|
|
|
function deleteCompanyFavorite(companyId: string) {
|
|
deleteFavoriteMutation({
|
|
variables: {
|
|
where: {
|
|
companyId: {
|
|
equals: companyId,
|
|
},
|
|
},
|
|
},
|
|
refetchQueries: [
|
|
getOperationName(GET_FAVORITES) ?? '',
|
|
getOperationName(GET_COMPANY) ?? '',
|
|
],
|
|
});
|
|
}
|
|
|
|
function deletePersonFavorite(personId: string) {
|
|
deleteFavoriteMutation({
|
|
variables: {
|
|
where: {
|
|
personId: {
|
|
equals: personId,
|
|
},
|
|
},
|
|
},
|
|
refetchQueries: [
|
|
getOperationName(GET_FAVORITES) ?? '',
|
|
getOperationName(GET_PERSON) ?? '',
|
|
],
|
|
});
|
|
}
|
|
|
|
return {
|
|
insertCompanyFavorite,
|
|
insertPersonFavorite,
|
|
deleteCompanyFavorite,
|
|
deletePersonFavorite,
|
|
};
|
|
}
|