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

Added UserAvatar in userlist and users page #8912

Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/components/Common/UserAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function UserAutocomplete(props: UserSearchProps) {
)}
optionLabel={formatName}
optionIcon={userOnlineDot}
optionImage={(option) => option.read_profile_picture_url}
optionDescription={(option) =>
`${option.user_type} - ${option.username}`
}
Expand Down
54 changes: 37 additions & 17 deletions src/components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import FormField from "./FormField";
import { classNames } from "../../../Utils/utils";
import { dropdownOptionClassNames } from "../MultiSelectMenuV2";
import { useTranslation } from "react-i18next";

import { Avatar } from "@/components/Common/Avatar";
type OptionCallback<T, R> = (option: T) => R;

type AutocompleteFormFieldProps<T, V> = FormFieldBaseProps<V> & {
Expand All @@ -24,6 +24,7 @@ type AutocompleteFormFieldProps<T, V> = FormFieldBaseProps<V> & {
optionValue?: OptionCallback<T, V>;
optionDescription?: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionImage?: OptionCallback<T, string | undefined>;
optionDisabled?: OptionCallback<T, boolean>;
minQueryLength?: number;
onQuery?: (query: string) => void;
Expand All @@ -50,6 +51,7 @@ const AutocompleteFormField = <T, V>(
placeholder={props.placeholder}
optionLabel={props.optionLabel}
optionIcon={props.optionIcon}
optionImage={props.optionImage}
optionValue={props.optionValue}
optionDescription={props.optionDescription}
optionDisabled={props.optionDisabled}
Expand All @@ -74,6 +76,7 @@ type AutocompleteProps<T, V = T> = {
placeholder?: string;
optionLabel: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionImage?: OptionCallback<T, string | undefined>;
optionValue?: OptionCallback<T, V>;
optionDescription?: OptionCallback<T, React.ReactNode>;
optionDisabled?: OptionCallback<T, boolean>;
Expand Down Expand Up @@ -118,6 +121,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
description,
search: label.toLowerCase(),
icon: props.optionIcon?.(option),
image: props.optionImage?.(option),
value: props.optionValue ? props.optionValue(option) : option,
disabled: props.optionDisabled?.(option),
};
Expand All @@ -137,6 +141,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
description: undefined,
search: query.toLowerCase(),
icon: <CareIcon icon="l-plus" />,
image: undefined,
value: query,
disabled: undefined,
},
Expand Down Expand Up @@ -236,24 +241,39 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
>
{({ focus }) => (
<div className="flex flex-col">
<div className="flex justify-between">
<span>{option.label}</span>
<span>{option.icon}</span>
</div>
{option.description && (
<div
className={classNames(
"text-sm font-normal",
option.disabled
? "text-secondary-700"
: focus
? "text-primary-200"
: "text-secondary-700",
<div className="flex items-center">
<div className="flex flex-col">
<div className="relative">
<Avatar
className="mr-2 h-11 w-11 rounded-full"
name={option.label}
imageUrl={option.image}
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
/>
<span className="absolute bottom-0 right-0 z-10">
{option.icon}
</span>
</div>
</div>
<div className="w-full">
<div className="flex justify-between">
<span>{option.label}</span>
</div>
{option.description && (
<div
className={classNames(
"text-sm font-normal",
option.disabled
? "text-secondary-700"
: focus
? "text-primary-200"
: "text-secondary-700",
)}
>
{option.description}
</div>
)}
>
{option.description}
</div>
)}
</div>
</div>
)}
</ComboboxOption>
Expand Down
10 changes: 9 additions & 1 deletion src/components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import request from "../../Utils/request/request";
import useQuery from "../../Utils/request/useQuery";
import {
classNames,
formatDisplayName,
formatName,
isUserOnline,
relativeTime,
Expand All @@ -36,7 +37,7 @@ import UnlinkFacilityDialog from "./UnlinkFacilityDialog";
import UserDeleteDialog from "./UserDeleteDialog";
import UserFilter from "./UserFilter";
import { showUserDelete } from "../../Utils/permissions";

import { Avatar } from "../Common/Avatar";
import Loading from "@/components/Common/Loading";
export default function ManageUsers() {
const { t } = useTranslation();
Expand Down Expand Up @@ -196,6 +197,13 @@ export default function ManageUsers() {
<div className="relative block h-full overflow-visible rounded-lg bg-white shadow hover:border-primary-500">
<div className="flex h-full flex-col justify-between @container">
<div className="px-6 py-4">
<div className="mb-2 flex-none text-lg">
<Avatar
name={formatDisplayName(user)}
imageUrl={user.read_profile_picture_url}
className="mb-2 h-12 w-12 rounded-full text-black lg:mb-0"
/>
</div>
<div className="flex flex-col flex-wrap justify-between gap-3 @sm:flex-row">
{user.username && (
<div
Expand Down
1 change: 1 addition & 0 deletions src/components/Users/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type UserBareMinimum = {
email: string;
user_type: UserRole;
last_login: string | undefined;
read_profile_picture_url?: string;
};

export type GenderType = "Male" | "Female" | "Transgender";
Expand Down
Loading