Skip to content

Commit

Permalink
fix: ensure default viewContact logic is skipped if contact.id matche…
Browse files Browse the repository at this point in the history
…s user
  • Loading branch information
trevor-anderson committed Jun 28, 2023
1 parent be6a20b commit 043b1fb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Avatar/ContactAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { useNavigate } from "react-router-dom";
import Tooltip from "@mui/material/Tooltip";
import { authenticatedUserStore } from "@cache/authenticatedUserStore";
import { Avatar, type AvatarProps } from "./Avatar";
import type { Profile } from "@graphql/types";

/**
* Will display an Avatar along with the Contact's `displayName`
* - If `viewContactOnClick` is not explicitly set to false, onClick event
* handler will nav to `/home/contacts/:id`
* > Typically, `viewContactOnClick` will be
* handler will nav to `/home/contacts/:id` if `contact.id` is not the
* authenticated User's ID.
* > If set explicitly, typically `viewContactOnClick` will be
* > - `TRUE if contact={item.assignedTo}`
* > - `FALSE if contact={item.createdBy}`
* - Can set `showDisplayName` = false if displayName is undesirable.
*/
export const ContactAvatar = ({
contact,
viewContactOnClick = true,
viewContactOnClick,
showDisplayName = true,
...avatarProps
}: ContactAvatarProps) => {
const nav = useNavigate();
const { id: authenticatedUserID } = authenticatedUserStore.useSubToStore();

viewContactOnClick ??= contact.id !== authenticatedUserID;

const commonAvatarProps = {
profile: contact.profile,
Expand Down

0 comments on commit 043b1fb

Please sign in to comment.