fix: stacked avatar colors (#1361)

This commit is contained in:
Ephraim Duncan
2024-10-09 01:25:56 +00:00
committed by GitHub
parent a2db5e9642
commit 2c1a18bafc
6 changed files with 74 additions and 32 deletions

View File

@ -1,9 +1,11 @@
'use client'; 'use client';
import { useMemo } from 'react';
import { Trans } from '@lingui/macro'; import { Trans } from '@lingui/macro';
import { useLingui } from '@lingui/react'; import { useLingui } from '@lingui/react';
import { getRecipientType } from '@documenso/lib/client-only/recipient-type'; import { RecipientStatusType, getRecipientType } from '@documenso/lib/client-only/recipient-type';
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles'; import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter'; import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter';
import type { DocumentStatus, Recipient } from '@documenso/prisma/client'; import type { DocumentStatus, Recipient } from '@documenso/prisma/client';
@ -29,24 +31,26 @@ export const StackAvatarsWithTooltip = ({
const { _ } = useLingui(); const { _ } = useLingui();
const waitingRecipients = recipients.filter( const waitingRecipients = recipients.filter(
(recipient) => getRecipientType(recipient) === 'waiting', (recipient) => getRecipientType(recipient) === RecipientStatusType.WAITING,
); );
const openedRecipients = recipients.filter( const openedRecipients = recipients.filter(
(recipient) => getRecipientType(recipient) === 'opened', (recipient) => getRecipientType(recipient) === RecipientStatusType.OPENED,
); );
const completedRecipients = recipients.filter( const completedRecipients = recipients.filter(
(recipient) => getRecipientType(recipient) === 'completed', (recipient) => getRecipientType(recipient) === RecipientStatusType.COMPLETED,
); );
const uncompletedRecipients = recipients.filter( const uncompletedRecipients = recipients.filter(
(recipient) => getRecipientType(recipient) === 'unsigned', (recipient) => getRecipientType(recipient) === RecipientStatusType.UNSIGNED,
); );
const sortedRecipients = useMemo(() => recipients.sort((a, b) => a.id - b.id), [recipients]);
return ( return (
<PopoverHover <PopoverHover
trigger={children || <StackAvatars recipients={recipients} />} trigger={children || <StackAvatars recipients={sortedRecipients} />}
contentProps={{ contentProps={{
className: 'flex flex-col gap-y-5 py-2', className: 'flex flex-col gap-y-5 py-2',
side: position, side: position,
@ -65,7 +69,7 @@ export const StackAvatarsWithTooltip = ({
type={getRecipientType(recipient)} type={getRecipientType(recipient)}
fallbackText={recipientAbbreviation(recipient)} fallbackText={recipientAbbreviation(recipient)}
/> />
<div className=""> <div>
<p className="text-muted-foreground text-sm">{recipient.email}</p> <p className="text-muted-foreground text-sm">{recipient.email}</p>
<p className="text-muted-foreground/70 text-xs"> <p className="text-muted-foreground/70 text-xs">
{_(RECIPIENT_ROLES_DESCRIPTION[recipient.role].roleName)} {_(RECIPIENT_ROLES_DESCRIPTION[recipient.role].roleName)}

View File

@ -1,6 +1,9 @@
import React from 'react'; import React from 'react';
import { getRecipientType } from '@documenso/lib/client-only/recipient-type'; import {
getExtraRecipientsType,
getRecipientType,
} from '@documenso/lib/client-only/recipient-type';
import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter'; import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter';
import type { Recipient } from '@documenso/prisma/client'; import type { Recipient } from '@documenso/prisma/client';
@ -13,20 +16,27 @@ export function StackAvatars({ recipients }: { recipients: Recipient[] }) {
const remainingItems = recipients.length - itemsToRender.length; const remainingItems = recipients.length - itemsToRender.length;
return itemsToRender.map((recipient: Recipient, index: number) => { return itemsToRender.map((recipient: Recipient, index: number) => {
const first = index === 0 ? true : false; const first = index === 0;
const lastItemText = if (index === 4 && remainingItems > 0) {
index === itemsToRender.length - 1 && remainingItems > 0 return (
? `+${remainingItems + 1}` <StackAvatar
: undefined; key="extra-recipient"
first={first}
zIndex={String(zIndex - index * 10)}
type={getExtraRecipientsType(recipients.slice(4))}
fallbackText={`+${remainingItems + 1}`}
/>
);
}
return ( return (
<StackAvatar <StackAvatar
key={recipient.id} key={recipient.id}
first={first} first={first}
zIndex={String(zIndex - index * 10)} zIndex={String(zIndex - index * 10)}
type={lastItemText && index === 4 ? 'unsigned' : getRecipientType(recipient)} type={getRecipientType(recipient)}
fallbackText={lastItemText ? lastItemText : recipientAbbreviation(recipient)} fallbackText={recipientAbbreviation(recipient)}
/> />
); );
}); });

View File

@ -1,12 +1,19 @@
import type { Recipient } from '@documenso/prisma/client'; import type { Recipient } from '@documenso/prisma/client';
import { ReadStatus, RecipientRole, SendStatus, SigningStatus } from '@documenso/prisma/client'; import { ReadStatus, RecipientRole, SendStatus, SigningStatus } from '@documenso/prisma/client';
export enum RecipientStatusType {
COMPLETED = 'completed',
OPENED = 'opened',
WAITING = 'waiting',
UNSIGNED = 'unsigned',
}
export const getRecipientType = (recipient: Recipient) => { export const getRecipientType = (recipient: Recipient) => {
if ( if (
recipient.role === RecipientRole.CC || recipient.role === RecipientRole.CC ||
(recipient.sendStatus === SendStatus.SENT && recipient.signingStatus === SigningStatus.SIGNED) (recipient.sendStatus === SendStatus.SENT && recipient.signingStatus === SigningStatus.SIGNED)
) { ) {
return 'completed'; return RecipientStatusType.COMPLETED;
} }
if ( if (
@ -14,12 +21,33 @@ export const getRecipientType = (recipient: Recipient) => {
recipient.readStatus === ReadStatus.OPENED && recipient.readStatus === ReadStatus.OPENED &&
recipient.signingStatus === SigningStatus.NOT_SIGNED recipient.signingStatus === SigningStatus.NOT_SIGNED
) { ) {
return 'opened'; return RecipientStatusType.OPENED;
} }
if (recipient.sendStatus === 'SENT' && recipient.signingStatus === 'NOT_SIGNED') { if (
return 'waiting'; recipient.sendStatus === SendStatus.SENT &&
recipient.signingStatus === SigningStatus.NOT_SIGNED
) {
return RecipientStatusType.WAITING;
} }
return 'unsigned'; return RecipientStatusType.UNSIGNED;
};
export const getExtraRecipientsType = (extraRecipients: Recipient[]) => {
const types = extraRecipients.map((r) => getRecipientType(r));
if (types.includes(RecipientStatusType.UNSIGNED)) {
return RecipientStatusType.UNSIGNED;
}
if (types.includes(RecipientStatusType.OPENED)) {
return RecipientStatusType.OPENED;
}
if (types.includes(RecipientStatusType.WAITING)) {
return RecipientStatusType.WAITING;
}
return RecipientStatusType.COMPLETED;
}; };

View File

@ -789,7 +789,7 @@ msgstr "Unterzeichnung abschließen"
msgid "Complete Viewing" msgid "Complete Viewing"
msgstr "Betrachten abschließen" msgstr "Betrachten abschließen"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:58 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:62
#: apps/web/src/components/formatter/document-status.tsx:28 #: apps/web/src/components/formatter/document-status.tsx:28
msgid "Completed" msgid "Completed"
msgstr "Abgeschlossen" msgstr "Abgeschlossen"
@ -2143,7 +2143,7 @@ msgstr "Sobald Sie den QR-Code gescannt oder den Code manuell eingegeben haben,
msgid "Oops! Something went wrong." msgid "Oops! Something went wrong."
msgstr "Hoppla! Etwas ist schief gelaufen." msgstr "Hoppla! Etwas ist schief gelaufen."
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:97 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:101
msgid "Opened" msgid "Opened"
msgstr "Geöffnet" msgstr "Geöffnet"
@ -3636,7 +3636,7 @@ msgstr "Unable to sign in"
msgid "Unauthorized" msgid "Unauthorized"
msgstr "Unauthorized" msgstr "Unauthorized"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:112 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:116
msgid "Uncompleted" msgid "Uncompleted"
msgstr "Uncompleted" msgstr "Uncompleted"
@ -3848,7 +3848,7 @@ msgstr "Teams ansehen"
msgid "Viewed" msgid "Viewed"
msgstr "Angesehen" msgstr "Angesehen"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:82 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:86
msgid "Waiting" msgid "Waiting"
msgstr "Warten" msgstr "Warten"

View File

@ -784,7 +784,7 @@ msgstr "Complete Signing"
msgid "Complete Viewing" msgid "Complete Viewing"
msgstr "Complete Viewing" msgstr "Complete Viewing"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:58 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:62
#: apps/web/src/components/formatter/document-status.tsx:28 #: apps/web/src/components/formatter/document-status.tsx:28
msgid "Completed" msgid "Completed"
msgstr "Completed" msgstr "Completed"
@ -2138,7 +2138,7 @@ msgstr "Once you have scanned the QR code or entered the code manually, enter th
msgid "Oops! Something went wrong." msgid "Oops! Something went wrong."
msgstr "Oops! Something went wrong." msgstr "Oops! Something went wrong."
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:97 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:101
msgid "Opened" msgid "Opened"
msgstr "Opened" msgstr "Opened"
@ -3631,7 +3631,7 @@ msgstr "Unable to sign in"
msgid "Unauthorized" msgid "Unauthorized"
msgstr "Unauthorized" msgstr "Unauthorized"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:112 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:116
msgid "Uncompleted" msgid "Uncompleted"
msgstr "Uncompleted" msgstr "Uncompleted"
@ -3843,7 +3843,7 @@ msgstr "View teams"
msgid "Viewed" msgid "Viewed"
msgstr "Viewed" msgstr "Viewed"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:82 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:86
msgid "Waiting" msgid "Waiting"
msgstr "Waiting" msgstr "Waiting"

View File

@ -789,7 +789,7 @@ msgstr "Compléter la signature"
msgid "Complete Viewing" msgid "Complete Viewing"
msgstr "Compléter la visualisation" msgstr "Compléter la visualisation"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:58 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:62
#: apps/web/src/components/formatter/document-status.tsx:28 #: apps/web/src/components/formatter/document-status.tsx:28
msgid "Completed" msgid "Completed"
msgstr "Complété" msgstr "Complété"
@ -2143,7 +2143,7 @@ msgstr "Une fois que vous avez scanné le code QR ou saisi le code manuellement,
msgid "Oops! Something went wrong." msgid "Oops! Something went wrong."
msgstr "Oups ! Quelque chose a mal tourné." msgstr "Oups ! Quelque chose a mal tourné."
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:97 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:101
msgid "Opened" msgid "Opened"
msgstr "Ouvert" msgstr "Ouvert"
@ -3636,7 +3636,7 @@ msgstr "Impossible de se connecter"
msgid "Unauthorized" msgid "Unauthorized"
msgstr "Non autorisé" msgstr "Non autorisé"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:112 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:116
msgid "Uncompleted" msgid "Uncompleted"
msgstr "Non complet" msgstr "Non complet"
@ -3848,7 +3848,7 @@ msgstr "Voir les équipes"
msgid "Viewed" msgid "Viewed"
msgstr "Vu" msgstr "Vu"
#: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:82 #: apps/web/src/components/(dashboard)/avatar/stack-avatars-with-tooltip.tsx:86
msgid "Waiting" msgid "Waiting"
msgstr "En attente" msgstr "En attente"