Skip to content

Commit

Permalink
prevent user from changing avatar if it is google or discord user
Browse files Browse the repository at this point in the history
  • Loading branch information
radekm2000 committed May 8, 2024
1 parent 504a6fe commit 8de0669
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
50 changes: 26 additions & 24 deletions client/ecommerce/src/components/pages/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import toast from "react-hot-toast";
import { useLocation } from "wouter";
import { useFetchUserInfo } from "../../hooks/useFetchUserInfo";
import { RenderAvatar } from "../RenderAvatar";
import { isAbleToChangeAvatar } from "../../utils/checkIfUserCanChangeAvatar";

type FormData = {
country: string;
Expand Down Expand Up @@ -135,30 +136,31 @@ export const EditProfile = () => {
) : (
<RenderAvatar width="64px" height="64px" user={user} />
)}

<Button
component="label"
size="small"
variant="outlined"
sx={{
border: "1px solid #007782",
textTransform: "none",
padding: "8px",
color: "#007782",
alignItems: "center",
justifyContent: "center",
height: "40%",
}}
>
Choose photo
<Input
id="upload-photo"
name="upload-photo"
type="file"
style={{ display: "none" }}
onChange={(e) => handleAvatarChange(e)}
/>
</Button>
{isAbleToChangeAvatar(user) && (
<Button
component="label"
size="small"
variant="outlined"
sx={{
border: "1px solid #007782",
textTransform: "none",
padding: "8px",
color: "#007782",
alignItems: "center",
justifyContent: "center",
height: "40%",
}}
>
Choose photo
<Input
id="upload-photo"
name="upload-photo"
type="file"
style={{ display: "none" }}
onChange={(e) => handleAvatarChange(e)}
/>
</Button>
)}
</Box>
</Box>
<Box
Expand Down
5 changes: 5 additions & 0 deletions client/ecommerce/src/utils/checkIfUserCanChangeAvatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { User } from "../types/types";

export const isAbleToChangeAvatar = (user: User) => {
return user.googleId !== null || user.role !== "discordUser";
};

0 comments on commit 8de0669

Please sign in to comment.