Skip to content

Commit

Permalink
feat(admin): double check before ban/deactivate users (#165)
Browse files Browse the repository at this point in the history
* feat(admin): fouble check before ban/deactivate

* feat(admin): fouble check before ban/deactivate
  • Loading branch information
AhmedHamdiy authored Dec 21, 2024
1 parent c9dc909 commit 72e0ea4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
/* tslint:disable */

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/protected-route/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type prortectedRouteType = {
function ProtectedRoute({
children,
allowedRoles,
userRole,
userRole
}: prortectedRouteType) {
const navigate = useNavigate();
const { isAuth, isPending } = useAuthStatus();
Expand Down
45 changes: 41 additions & 4 deletions app/src/features/admin/components/UserCardButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import styled from "styled-components";
import { userStatus } from "types/admin";
import Button from "@components/Button";
import Modal from "@components/Modal";
import { useState } from "react";
import { set } from "react-hook-form";

interface Props {
status: userStatus;
Expand All @@ -16,24 +19,34 @@ const ButtonContainer = styled.div`

function UserCardButton(props: Props) {
const { status, onChangeStatus } = props;
const [isModalOpen, setIsModalOpen] = useState(false);
const [action, setAction] = useState("");
let renderedButtons;
const handleDeactivate = () => {
setAction("deactivate");
setIsModalOpen(true);
};
const handleBan = () => {
setAction("ban");
setIsModalOpen(true);
};
switch (status) {
case userStatus.active:
renderedButtons = (
<>
<Button
onClick={() => onChangeStatus(userStatus.deactivated)}
onClick={handleDeactivate}
$type="normal"
$width="15rem"
data-testid="deactivate-button"
>
Deactivate
</Button>
<Button
onClick={() => onChangeStatus(userStatus.banned)}
$type="danger"
$width="15rem"
datatype="ban-button"
onClick={handleBan}
>
Ban
</Button>
Expand All @@ -52,7 +65,7 @@ function UserCardButton(props: Props) {
Activate
</Button>
<Button
onClick={() => onChangeStatus(userStatus.banned)}
onClick={handleBan}
$type="danger"
$width="15rem"
data-testid="ban-button"
Expand All @@ -66,7 +79,31 @@ function UserCardButton(props: Props) {
renderedButtons = null;
break;
}
return <ButtonContainer>{renderedButtons}</ButtonContainer>;
return (
<>
<Modal
isOpen={isModalOpen}
message={`You are going to ${action} this user${action === "ban" ? "for ever" : ""}.`}
title={`${action} User`}
onClose={() => setIsModalOpen(false)}
>
<Button
onClick={() =>
onChangeStatus(
action === "ban" ? userStatus.banned : userStatus.deactivated
)
}
$type="danger"
$width="10rem"
data-testid="ban-button"
style={{ margin: "auto" }}
>
{action}
</Button>
</Modal>
<ButtonContainer>{renderedButtons}</ButtonContainer>
</>
);
}

export default UserCardButton;
14 changes: 7 additions & 7 deletions app/src/features/chats/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ function MessageContent() {
media,
contentType,
chatType,
isAppropriate,
isAppropriate
} = useMessageContext();

const { searchTerm, searchResults } = useAppSelector((state) => state.search);
const { MoveToReplyMessage } = useOptionListAction({
id,
content,
parentMessageId,
parentMessageId
});

const isGifOrSticker =
media && (contentType === "GIF" || contentType === "sticker");

const isFile = media && !(contentType === "GIF" || contentType === "sticker");
const filteredContent =
(chatType === "group" || chatType === "channel") && !isAppropriate
? content
: "🚫️ This mesaage has unappropriate content";
console.log("isAppropriate", isAppropriate);
const filteredContent = isAppropriate
? content
: "🚫️ This mesaage has unappropriate content";

return (
<Container>
Expand All @@ -68,7 +68,7 @@ function MessageContent() {
)}
{isGifOrSticker && <Gif src={media} loading="lazy" />}
{isFile && <FileViewer file={media} />}
{RenderWithHighlight(content, searchTerm, searchResults, id)}
{RenderWithHighlight(filteredContent, searchTerm, searchResults, id)}
</Container>
);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/features/chats/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function parseChatsToState(chatData?: any) {
_id: incomingLastMessage?.id,
content: incomingLastMessage?.content,
senderId: incomingLastMessage?.senderId,
timestamp: incomingLastMessage?.timestamp
timestamp: incomingLastMessage?.timestamp,
contentType: incomingLastMessage?.contentType
},

messages: [],
Expand Down
5 changes: 3 additions & 2 deletions app/src/state/messages/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface DetailedChatInterface extends Chat {
content: string;
senderId: string;
timestamp: string;
contentType: string;
};
name?: string;
isBlocked?: boolean;
Expand Down Expand Up @@ -77,10 +78,10 @@ const chatsSlice = createSlice({
const chat = getChatByID({ chats: state.chats, chatID: chatId });

if (chat?.type === "private" && chat?.isBlocked) return;
const { _id, content, senderId, timestamp } = message;
const { _id, content, senderId, timestamp, contentType } = message;

if (chat) {
chat.lastMessage = { _id, content, senderId, timestamp };
chat.lastMessage = { _id, content, senderId, timestamp, contentType };
chat.messages.push(message);
}
},
Expand Down

0 comments on commit 72e0ea4

Please sign in to comment.