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

feat: Added Avatars and profile pictures in userAutoComplete #8892

Closed
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
5 changes: 4 additions & 1 deletion src/Components/Common/UserAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { UserRole } from "../../Common/constants";
import { useEffect, useState } from "react";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import { UserBareMinimum } from "../Users/models";
import { UserBareMinimum, UserModel } from "../Users/models";

type BaseProps = FormFieldBaseProps<UserBareMinimum> & {
placeholder?: string;
Expand Down Expand Up @@ -80,6 +80,9 @@ export default function UserAutocomplete(props: UserSearchProps) {
)}
optionLabel={formatName}
optionIcon={userOnlineDot}
optionProfilePicture={(option: UserModel) =>
option.read_profile_picture_url
}
optionDescription={(option) =>
`${option.user_type} - ${option.username}`
}
Expand Down
18 changes: 15 additions & 3 deletions src/Components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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;

Expand All @@ -24,6 +25,7 @@ type AutocompleteFormFieldProps<T, V> = FormFieldBaseProps<V> & {
optionValue?: OptionCallback<T, V>;
optionDescription?: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionProfilePicture?: any;
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
optionDisabled?: OptionCallback<T, boolean>;
minQueryLength?: number;
onQuery?: (query: string) => void;
Expand Down Expand Up @@ -74,6 +76,7 @@ type AutocompleteProps<T, V = T> = {
placeholder?: string;
optionLabel: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionProfilePicture?: any;
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
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),
profilePicture: props.optionProfilePicture?.(option) ?? null,
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" />,
profilePicture: null,
value: query,
disabled: undefined,
},
Expand Down Expand Up @@ -236,9 +241,16 @@ 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 className="flex items-center">
<Avatar
className="mr-2 h-7 w-7 rounded-full"
name={option.label}
imageUrl={option.profilePicture}
/>
<div className="flex w-full justify-between">
<span>{option.label}</span>
<span>{option.icon}</span>
</div>
</div>
{option.description && (
<div
Expand Down
9 changes: 9 additions & 0 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
formatName,
isUserOnline,
relativeTime,
formatDisplayName,
} from "../../Utils/utils";
import { FacilitySelect } from "../Common/FacilitySelect";
import Pagination from "../Common/Pagination";
Expand All @@ -38,6 +39,7 @@ import UserFilter from "./UserFilter";
import { showUserDelete } from "../../Utils/permissions";

import Loading from "@/Components/Common/Loading";
import { Avatar } from "../Common/Avatar";
export default function ManageUsers() {
const { t } = useTranslation();
const { width } = useWindowDimensions();
Expand Down Expand Up @@ -196,6 +198,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
Loading