Skip to content

Commit

Permalink
handle updating statement on detail changes (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptrhnk authored Oct 25, 2023
1 parent 2d3ce79 commit aad5306
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,35 @@ export const EntityDetail: React.FC<EntityDetail> = ({ detailId }) => {
);
}, [entity]);

const {
status: statusStatement,
data: statement,
error: statementError,
isFetching: isFetchingStatement,
} = useQuery(
["statement", statementId],
async () => {
const res = await api.statementGet(statementId);
return res.data;
},
{ enabled: !!statementId && api.isLoggedIn() }
);

const updateEntityMutation = useMutation(
async (changes: any) => await api.entityUpdate(detailId, changes),
{
onSuccess: (data, variables) => {
queryClient.invalidateQueries(["entity"]);

if (
statementId &&
statement?.entities &&
entity &&
Object.keys(statement.entities).includes(entity.id)
) {
queryClient.invalidateQueries(["statement"]);
}

if (
variables.references !== undefined ||
variables.detail !== undefined ||
Expand All @@ -225,9 +248,7 @@ export const EntityDetail: React.FC<EntityDetail> = ({ detailId }) => {
if (entity?.class === EntityEnums.Class.Territory) {
queryClient.invalidateQueries(["tree"]);
}
if (entity?.class === EntityEnums.Class.Statement) {
queryClient.invalidateQueries(["statement"]);
}

queryClient.invalidateQueries(["territory"]);
queryClient.invalidateQueries(["bookmarks"]);
}
Expand Down

0 comments on commit aad5306

Please sign in to comment.