Skip to content

Commit

Permalink
🐛 Fix normal user can set privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmaa-204 committed Dec 21, 2024
1 parent 64ef39f commit 266ae17
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app/src/features/groups/GroupType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Container = styled.div`
`;

function GroupType() {
const { group, chatId } = useGroupInfo();
const { group, chatId, isCurrUserAdmin } = useGroupInfo();
const { setPrivacy } = useSocket();
const [selectedGroupType, setSelectedGroupType] = useState<
"private" | "public"
Expand All @@ -35,12 +35,14 @@ function GroupType() {
selected={selectedGroupType === "private"}
onClick={() => handleSelection("private")}
groupType={group?.type}
isAdmin={isCurrUserAdmin}
/>
<GroupTypeOption
type="public"
selected={selectedGroupType === "public"}
onClick={() => handleSelection("public")}
groupType={group?.type}
isAdmin={isCurrUserAdmin}
/>
</Container>
);
Expand Down
23 changes: 15 additions & 8 deletions app/src/features/groups/GroupTypeOption.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import styled from "styled-components";

const Option = styled.div`
const Option = styled.div<{ disabled: boolean }>`
display: flex;
align-items: center;
gap: 1rem;
cursor: pointer;
cursor: ${({ disabled }) => (disabled ? "not-allowed" : "pointer")};
`;

const RadioButton = styled.div<{ selected: boolean }>`
const RadioButton = styled.button<{ selected: boolean; disabled: boolean }>`
background: transparent;
flex-shrink: 0;
width: 1.2rem;
height: 1.2rem;
border-radius: 50%;
border: 2px solid
${({ selected }) =>
selected ? "var(--accent-color)" : "var(--color-text-secondary)"};
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
cursor: ${({ disabled }) => (disabled ? "not-allowed" : "pointer")};
&::after {
content: "";
Expand Down Expand Up @@ -49,6 +54,7 @@ const Description = styled.p`
interface GroupTypeOptionProps {
type: "private" | "public";
selected: boolean;
isAdmin: boolean;
onClick: () => void;
groupType: string | undefined;
}
Expand All @@ -57,10 +63,11 @@ const GroupTypeOption = ({
type,
selected,
onClick,
groupType
groupType,
isAdmin
}: GroupTypeOptionProps) => (
<Option onClick={onClick}>
<RadioButton selected={selected} />
<Option disabled={!isAdmin} onClick={onClick}>
<RadioButton selected={selected} disabled={!isAdmin} />
<Details>
<Title>{`${type.charAt(0).toUpperCase() + type.slice(1)} ${groupType}`}</Title>
<Description>
Expand Down
4 changes: 4 additions & 0 deletions app/src/sockets/SocketProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ function SocketProvider({ children }: SocketProviderProps) {
console.log("SET_PERMISSION_SERVER", chatId, type, who);
queryClient.invalidateQueries({ queryKey: ["chats"] });
});
socket.on("SET_PRIVACY_SERVER", ({ chatId, privacy }) => {
console.log("SET_PERMISSION_SERVER", chatId, privacy);
queryClient.invalidateQueries({ queryKey: ["chats"] });
});

socket.on("typing", (isTyping, message) =>
handleIsTyping(dispatch, isTyping, message.chatId)
Expand Down

0 comments on commit 266ae17

Please sign in to comment.