Skip to content

Commit

Permalink
add subscription to common member log
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Nov 9, 2023
1 parent 1161230 commit 67e8d5e
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions src/pages/OldCommon/hooks/useCommonMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,38 +184,43 @@ export const useCommonMember = (options: Options = {}): Return => {
return;
}

const unsubscribe =
CommonService.subscribeToCommonMemberByCommonIdAndUserId(
commonId,
userId,
(commonMember, { isAdded, isRemoved }) => {
let data: State["data"] = null;

if (isAdded) {
CommonEventEmitter.emit(CommonEvent.ProjectUpdated, {
commonId,
hasMembership: true,
try {
console.log({ commonId, userId });
const unsubscribe =
CommonService.subscribeToCommonMemberByCommonIdAndUserId(
commonId,
userId,
(commonMember, { isAdded, isRemoved }) => {
let data: State["data"] = null;

if (isAdded) {
CommonEventEmitter.emit(CommonEvent.ProjectUpdated, {
commonId,
hasMembership: true,
});
}
if (!isRemoved) {
data = {
...commonMember,
...generateCirclesDataForCommonMember(
governanceCircles,
commonMember.circleIds,
),
};
}

setState({
loading: false,
fetched: true,
data,
});
}
if (!isRemoved) {
data = {
...commonMember,
...generateCirclesDataForCommonMember(
governanceCircles,
commonMember.circleIds,
),
};
}

setState({
loading: false,
fetched: true,
data,
});
},
);
},
);

return unsubscribe;
return unsubscribe;
} catch (error) {
console.error(error);
}
}, [withSubscription, commonId, userId, governanceCircles]);

return {
Expand Down

0 comments on commit 67e8d5e

Please sign in to comment.