Skip to content

Commit

Permalink
Restrict pin icon visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghaAnirban005 committed Dec 1, 2024
1 parent cc9afe1 commit 43807a7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions packages/react/src/hooks/useRCAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const useRCAuth = () => {
);
const setPassword = useUserStore((state) => state.setPassword);
const setEmailorUser = useUserStore((state) => state.setEmailorUser);
const setUserPermissions = useUserStore((state) => state.setUserPermissions);
const setUserPinPermissions = useUserStore(
(state) => state.setUserPinPermissions
);
const dispatchToastMessage = useToastBarDispatch();

const handleLogin = async (userOrEmail, password, code) => {
Expand Down Expand Up @@ -58,7 +60,7 @@ export const useRCAuth = () => {
setIsTotpModalOpen(false);
setEmailorUser(null);
setPassword(null);
setUserPermissions(permissions);
setUserPinPermissions(permissions.update[150]);
dispatchToastMessage({
type: 'success',
message: 'Successfully logged in',
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/store/userStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const useUserStore = create((set) => ({
setPassword: (password) => set(() => ({ password })),
emailoruser: null,
setEmailorUser: (emailoruser) => set(() => ({ emailoruser })),
roles: {},
roles: [],
setRoles: (roles) => set((state) => ({ ...state, roles })),
userPermissions: {},
setUserPermissions: (userPermissions) =>
set((state) => ({ ...state, userPermissions })),
userPinPermissions: {},
setUserPinPermissions: (userPinPermissions) =>
set((state) => ({ ...state, userPinPermissions })),
showCurrentUserInfo: false,
setShowCurrentUserInfo: (showCurrentUserInfo) =>
set(() => ({ showCurrentUserInfo })),
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/views/Message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Message = ({
const authenticatedUserUsername = useUserStore((state) => state.username);
const userRoles = useUserStore((state) => state.roles);
const pinPermissions = useUserStore(
(state) => state.userPermissions.update[150].roles
(state) => state.userPinPermissions.roles
);
const [setMessageToReport, toggleShowReportMessage] = useMessageStore(
(state) => [state.setMessageToReport, state.toggleShowReportMessage]
Expand All @@ -72,7 +72,6 @@ const Message = ({
const styles = getMessageStyles(theme);
const bubbleStyles = useBubbleStyles(isMe);
const pinRoles = new Set(pinPermissions);
const isAllowedToPin = userRoles.some((role) => pinRoles.has(role));

const variantStyles =
!isInSidebar && variantOverrides === 'bubble' ? bubbleStyles : {};
Expand Down Expand Up @@ -206,7 +205,8 @@ const Message = ({
message={message}
isEditing={editMessage._id === message._id}
authenticatedUserId={authenticatedUserId}
isAllowedToPin={isAllowedToPin}
userRoles={userRoles}
pinRoles={pinRoles}
handleOpenThread={handleOpenThread}
handleDeleteMessage={handleDeleteMessage}
handleStarMessage={handleStarMessage}
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/views/Message/MessageToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const MessageToolbox = ({
style = {},
isThreadMessage = false,
authenticatedUserId,
isAllowedToPin,
userRoles,
pinRoles,
handleOpenThread,
handleEmojiClick,
handlePinMessage,
Expand Down Expand Up @@ -68,6 +69,7 @@ export const MessageToolbox = ({
setShowDeleteModal(false);
};

const isAllowedToPin = userRoles.some((role) => pinRoles.has(role));
const options = useMemo(
() => ({
reply: {
Expand Down

0 comments on commit 43807a7

Please sign in to comment.