Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to set profile pictures #8606

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 2 additions & 50 deletions src/Components/Common/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import CareIcon from "@/CAREUI/icons/CareIcon";
import { cn } from "@/lib/utils";
import React from "react";
import { useTranslation } from "react-i18next";

const colors: string[] = [
"#E6F3FF", // Light Blue
Expand Down Expand Up @@ -52,11 +50,6 @@ interface AvatarProps {
className?: string;
}

interface EditableAvatarProps extends AvatarProps {
editable?: boolean;
onClick?: () => void;
}

const Avatar: React.FC<AvatarProps> = ({
id,
colors: propColors,
Expand Down Expand Up @@ -108,46 +101,5 @@ const Avatar: React.FC<AvatarProps> = ({
);
};

const EditableAvatar: React.FC<EditableAvatarProps> = ({
id,
colors: propColors,
name,
imageUrl,
className,
editable = true,
onClick,
}) => {
const { t } = useTranslation();
return (
<div
id={id}
className={cn(
`group grid aspect-square h-full w-full place-items-center text-clip transition-all duration-200 ease-in-out [grid-template-areas:'stack']`,
editable && "cursor-pointer",
className,
)}
>
<Avatar
imageUrl={imageUrl}
name={name}
colors={propColors}
className="flex h-full w-full [grid-area:stack]"
/>

{editable && (
<div
className={
"flex h-full w-full cursor-pointer flex-col items-center justify-center bg-black text-sm text-secondary-300 opacity-0 transition-opacity [grid-area:stack] hover:opacity-60"
}
style={{ borderRadius: "calc(100% / 15)" }}
onClick={onClick}
>
<CareIcon icon="l-pen" className="text-lg" />
<span className="mt-2">{t(imageUrl ? "edit" : "upload")}</span>
</div>
)}
</div>
);
};

export { Avatar, EditableAvatar };
export { Avatar };
export type { AvatarProps };
53 changes: 53 additions & 0 deletions src/Components/Common/AvatarEditable.tsx
bodhish marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import CareIcon from "@/CAREUI/icons/CareIcon";
import { cn } from "@/lib/utils";
import { useTranslation } from "react-i18next";
import { AvatarProps, Avatar } from "@/Components/Common/Avatar";

interface AvatarEditableProps extends AvatarProps {
editable?: boolean;
onClick?: () => void;
}

const AvatarEditable: React.FC<AvatarEditableProps> = ({
sainak marked this conversation as resolved.
Show resolved Hide resolved
id,
colors: propColors,
name,
imageUrl,
className,
editable = true,
onClick,
}) => {
const { t } = useTranslation();
return (
<div
id={id}
className={cn(
`group grid aspect-square h-full w-full place-items-center text-clip transition-all duration-200 ease-in-out [grid-template-areas:'stack']`,
editable && "cursor-pointer",
className,
)}
>
<Avatar
imageUrl={imageUrl}
name={name}
colors={propColors}
className="flex h-full w-full [grid-area:stack]"
/>

{editable && (
<div
className={
"flex h-full w-full cursor-pointer flex-col items-center justify-center bg-black text-sm text-secondary-300 opacity-0 transition-opacity [grid-area:stack] hover:opacity-60"
}
style={{ borderRadius: "calc(100% / 15)" }}
onClick={onClick}
>
<CareIcon icon="l-pen" className="text-lg" />
<span className="mt-2">{t(imageUrl ? "edit" : "upload")}</span>
</div>
)}
</div>
);
};

export { AvatarEditable };
4 changes: 2 additions & 2 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { CameraFeedPermittedUserTypes } from "../../Utils/permissions.js";
import { FacilityStaffList } from "./FacilityStaffList.js";
import FacilityBlock from "./FacilityBlock.js";
import Loading from "@/Components/Common/Loading";
import { EditableAvatar } from "@/Components/Common/Avatar";
import { AvatarEditable } from "@/Components/Common/AvatarEditable";
import AvatarEditModal from "@/Components/Common/AvatarEditModal";
import careConfig from "@careConfig";
import uploadFile from "@/Utils/request/uploadFile";
Expand Down Expand Up @@ -201,7 +201,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
<div className="flex-col justify-between md:flex">
<div className="flex flex-1 flex-col">
<div className="flex flex-col items-start gap-4 md:flex-row">
<EditableAvatar
<AvatarEditable
id="facility-coverimage"
imageUrl={facilityData?.read_cover_image_url}
name={facilityData?.name ?? ""}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import request from "../../Utils/request/request";
import DateFormField from "../Form/FormFields/DateFormField";
import { validateRule } from "./UserAdd";
import { useTranslation } from "react-i18next";
import { EditableAvatar } from "@/Components/Common/Avatar";
import { AvatarEditable } from "@/Components/Common/AvatarEditable";
import Page from "@/Components/Common/components/Page";
import Loading from "@/Components/Common/Loading";
import AvatarEditModal from "@/Components/Common/AvatarEditModal";
Expand Down Expand Up @@ -534,7 +534,7 @@ export default function UserProfile() {
{t("are_non_editable_fields")}.
</p>
<div className="my-4 flex items-center">
<EditableAvatar
<AvatarEditable
id="user-profile-picture"
imageUrl={authUser?.read_profile_picture_url}
name={formatDisplayName(authUser)}
Expand Down
Loading