mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 03:32:13 +00:00
fix: buttons on friend request item
This commit is contained in:
parent
6f70b529a2
commit
22b66149b3
4 changed files with 143 additions and 154 deletions
|
@ -25,13 +25,13 @@ export const UserAddFriendsModal = ({
|
|||
const { sendFriendRequest, updateFriendRequestState, friendRequests } =
|
||||
useUserDetails();
|
||||
|
||||
const { showSuccessToast, showErrorToast } = useToast();
|
||||
const { showErrorToast } = useToast();
|
||||
|
||||
const handleClickAddFriend = () => {
|
||||
setIsAddingFriend(true);
|
||||
sendFriendRequest(friendCode)
|
||||
.then(() => {
|
||||
showSuccessToast(t("friend_request_sent"));
|
||||
setFriendCode("");
|
||||
})
|
||||
.catch(() => {
|
||||
showErrorToast("Não foi possível enviar o pedido de amizade");
|
||||
|
@ -41,133 +41,109 @@ export const UserAddFriendsModal = ({
|
|||
});
|
||||
};
|
||||
|
||||
const handleClickFriend = (userId: string) => {
|
||||
//onClose();
|
||||
//navigate(`/user/${userId}`);
|
||||
const handleClickRequest = (userId: string) => {
|
||||
resetAndClose();
|
||||
navigate(`/user/${userId}`);
|
||||
};
|
||||
|
||||
const handleClickSeeProfile = () => {
|
||||
onClose();
|
||||
resetAndClose();
|
||||
navigate(`/user/${friendCode}`);
|
||||
};
|
||||
|
||||
const handleClickCancelFriendRequest = (
|
||||
event: React.MouseEvent,
|
||||
userId: string
|
||||
) => {
|
||||
updateFriendRequestState(userId, "CANCEL")
|
||||
.then(() => {
|
||||
console.log("sucesso");
|
||||
})
|
||||
.catch(() => {
|
||||
showErrorToast("Falha ao cancelar convite");
|
||||
});
|
||||
const handleClickCancelFriendRequest = (userId: string) => {
|
||||
updateFriendRequestState(userId, "CANCEL").catch(() => {
|
||||
showErrorToast("Falha ao cancelar convite");
|
||||
});
|
||||
};
|
||||
|
||||
const handleClickAcceptFriendRequest = (
|
||||
event: React.MouseEvent,
|
||||
userId: string
|
||||
) => {
|
||||
const handleClickAcceptFriendRequest = (userId: string) => {
|
||||
updateFriendRequestState(userId, "ACCEPTED").catch(() => {
|
||||
showErrorToast("Falha ao aceitar convite");
|
||||
});
|
||||
};
|
||||
|
||||
const handleClickRefuseFriendRequest = (
|
||||
event: React.MouseEvent,
|
||||
userId: string
|
||||
) => {
|
||||
event.preventDefault();
|
||||
const handleClickRefuseFriendRequest = (userId: string) => {
|
||||
updateFriendRequestState(userId, "REFUSED").catch(() => {
|
||||
showErrorToast("Falha ao recusar convite");
|
||||
});
|
||||
};
|
||||
|
||||
const resetModal = () => {
|
||||
const resetAndClose = () => {
|
||||
setFriendCode("");
|
||||
};
|
||||
|
||||
const cleanFormAndClose = () => {
|
||||
resetModal();
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
visible={visible}
|
||||
title={t("add_friends")}
|
||||
onClose={cleanFormAndClose}
|
||||
<Modal visible={visible} title={t("add_friends")} onClose={resetAndClose}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
width: "500px",
|
||||
flexDirection: "column",
|
||||
gap: `${SPACING_UNIT * 2}px`,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
width: "500px",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
gap: `${SPACING_UNIT}px`,
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
label={t("friend_code")}
|
||||
value={friendCode}
|
||||
minLength={8}
|
||||
maxLength={8}
|
||||
containerProps={{ style: { width: "100%" } }}
|
||||
onChange={(e) => setFriendCode(e.target.value)}
|
||||
/>
|
||||
<Button
|
||||
disabled={isAddingFriend}
|
||||
style={{ alignSelf: "end" }}
|
||||
type="button"
|
||||
onClick={handleClickAddFriend}
|
||||
>
|
||||
{isAddingFriend ? t("sending") : t("send")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleClickSeeProfile}
|
||||
disabled={isAddingFriend}
|
||||
style={{ alignSelf: "end" }}
|
||||
type="button"
|
||||
>
|
||||
{t("see_profile")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: `${SPACING_UNIT * 2}px`,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
gap: `${SPACING_UNIT}px`,
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
label={t("friend_code")}
|
||||
value={friendCode}
|
||||
minLength={8}
|
||||
maxLength={8}
|
||||
containerProps={{ style: { width: "100%" } }}
|
||||
onChange={(e) => setFriendCode(e.target.value)}
|
||||
/>
|
||||
<Button
|
||||
disabled={isAddingFriend}
|
||||
style={{ alignSelf: "end" }}
|
||||
type="button"
|
||||
onClick={handleClickAddFriend}
|
||||
>
|
||||
{isAddingFriend ? t("sending") : t("send")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleClickSeeProfile}
|
||||
disabled={isAddingFriend}
|
||||
style={{ alignSelf: "end" }}
|
||||
type="button"
|
||||
>
|
||||
{t("see_profile")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: `${SPACING_UNIT * 2}px`,
|
||||
}}
|
||||
>
|
||||
<h3>Pendentes</h3>
|
||||
{friendRequests?.map((request) => {
|
||||
return (
|
||||
<UserFriendRequest
|
||||
key={request.id}
|
||||
displayName={request.displayName}
|
||||
isRequestSent={request.type === "SENT"}
|
||||
profileImageUrl={request.profileImageUrl}
|
||||
userId={request.id}
|
||||
onClickAcceptRequest={handleClickAcceptFriendRequest}
|
||||
onClickCancelRequest={handleClickCancelFriendRequest}
|
||||
onClickRefuseRequest={handleClickRefuseFriendRequest}
|
||||
onClickRequest={handleClickFriend}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<h3>Pendentes</h3>
|
||||
{friendRequests?.map((request) => {
|
||||
return (
|
||||
<UserFriendRequest
|
||||
key={request.id}
|
||||
displayName={request.displayName}
|
||||
isRequestSent={request.type === "SENT"}
|
||||
profileImageUrl={request.profileImageUrl}
|
||||
userId={request.id}
|
||||
onClickAcceptRequest={handleClickAcceptFriendRequest}
|
||||
onClickCancelRequest={handleClickCancelFriendRequest}
|
||||
onClickRefuseRequest={handleClickRefuseFriendRequest}
|
||||
onClickRequest={handleClickRequest}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -375,7 +375,7 @@ export function UserContent({
|
|||
<button
|
||||
key={friend.id}
|
||||
className={cn(
|
||||
styles.friendListItem,
|
||||
styles.friendListContainer,
|
||||
styles.profileContentBox
|
||||
)}
|
||||
onClick={() => handleOnClickFriend(friend.id)}
|
||||
|
|
|
@ -11,9 +11,9 @@ export interface UserFriendRequestProps {
|
|||
profileImageUrl: string | null;
|
||||
displayName: string;
|
||||
isRequestSent: boolean;
|
||||
onClickCancelRequest: (event: React.MouseEvent, userId: string) => void;
|
||||
onClickAcceptRequest: (event: React.MouseEvent, userId: string) => void;
|
||||
onClickRefuseRequest: (event: React.MouseEvent, userId: string) => void;
|
||||
onClickCancelRequest: (userId: string) => void;
|
||||
onClickAcceptRequest: (userId: string) => void;
|
||||
onClickRefuseRequest: (userId: string) => void;
|
||||
onClickRequest: (userId: string) => void;
|
||||
}
|
||||
|
||||
|
@ -28,57 +28,62 @@ export const UserFriendRequest = ({
|
|||
onClickRequest,
|
||||
}: UserFriendRequestProps) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={cn(styles.friendListItem, styles.profileContentBox)}
|
||||
onClick={() => onClickRequest(userId)}
|
||||
>
|
||||
<div className={styles.friendAvatarContainer}>
|
||||
{profileImageUrl ? (
|
||||
<img
|
||||
className={styles.profileAvatar}
|
||||
alt={displayName}
|
||||
src={profileImageUrl}
|
||||
/>
|
||||
) : (
|
||||
<PersonIcon size={24} />
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "flex-start",
|
||||
flex: "1",
|
||||
minWidth: 0,
|
||||
}}
|
||||
<div className={cn(styles.friendListContainer, styles.profileContentBox)}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.friendListButton}
|
||||
onClick={() => onClickRequest(userId)}
|
||||
>
|
||||
<p className={styles.friendListDisplayName}>{displayName}</p>
|
||||
<small>{isRequestSent ? "Pedido enviado" : "Pedido recebido"}</small>
|
||||
</div>
|
||||
{isRequestSent ? (
|
||||
<button
|
||||
className={styles.cancelRequestButton}
|
||||
onClick={(e) => onClickCancelRequest(e, userId)}
|
||||
<div className={styles.friendAvatarContainer}>
|
||||
{profileImageUrl ? (
|
||||
<img
|
||||
className={styles.profileAvatar}
|
||||
alt={displayName}
|
||||
src={profileImageUrl}
|
||||
/>
|
||||
) : (
|
||||
<PersonIcon size={24} />
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "flex-start",
|
||||
flex: "1",
|
||||
minWidth: 0,
|
||||
}}
|
||||
>
|
||||
<XCircleIcon size={28} />
|
||||
</button>
|
||||
) : (
|
||||
<>
|
||||
<button
|
||||
className={styles.acceptRequestButton}
|
||||
onClick={(e) => onClickAcceptRequest(e, userId)}
|
||||
>
|
||||
<CheckCircleIcon size={28} />
|
||||
</button>
|
||||
<p className={styles.friendListDisplayName}>{displayName}</p>
|
||||
<small>{isRequestSent ? "Pedido enviado" : "Pedido recebido"}</small>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div style={{ position: "absolute", right: "8px" }}>
|
||||
{isRequestSent ? (
|
||||
<button
|
||||
className={styles.cancelRequestButton}
|
||||
onClick={(e) => onClickRefuseRequest(e, userId)}
|
||||
onClick={() => onClickCancelRequest(userId)}
|
||||
>
|
||||
<XCircleIcon size={28} />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
) : (
|
||||
<>
|
||||
<button
|
||||
className={styles.acceptRequestButton}
|
||||
onClick={() => onClickAcceptRequest(userId)}
|
||||
>
|
||||
<CheckCircleIcon size={28} />
|
||||
</button>
|
||||
<button
|
||||
className={styles.cancelRequestButton}
|
||||
onClick={() => onClickRefuseRequest(userId)}
|
||||
>
|
||||
<XCircleIcon size={28} />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -178,21 +178,29 @@ export const gameListItem = style({
|
|||
},
|
||||
});
|
||||
|
||||
export const friendListItem = style({
|
||||
color: vars.color.body,
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`,
|
||||
export const friendListContainer = style({
|
||||
width: "100%",
|
||||
height: "54px",
|
||||
padding: "0 8px",
|
||||
transition: "all ease 0.2s",
|
||||
cursor: "pointer",
|
||||
position: "relative",
|
||||
":hover": {
|
||||
backgroundColor: "rgba(255, 255, 255, 0.15)",
|
||||
},
|
||||
});
|
||||
|
||||
export const friendListButton = style({
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
position: "absolute",
|
||||
cursor: "pointer",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
flexDirection: "row",
|
||||
color: vars.color.body,
|
||||
gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`,
|
||||
padding: "0 8px",
|
||||
});
|
||||
|
||||
export const gameInformation = style({
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
|
|
Loading…
Reference in a new issue