♻️ front: Implemented user display logic in grouped rows user molecule (#50)

This commit is contained in:
Eric Doughty-Papassideris
2024-04-21 22:10:35 +02:00
committed by ericlinagora
parent 0dec935e73
commit 035feada8d
2 changed files with 61 additions and 31 deletions
@@ -1,54 +1,54 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react';
import { ComponentStory } from '@storybook/react'; import { ComponentStory } from '@storybook/react';
import UserBlock from '.'; import UserBlock from '.';
import Avatar from '@atoms/avatar';
import { CheckIcon } from '@atoms/icons-agnostic'; import { CheckIcon } from '@atoms/icons-agnostic';
import type { UserType } from '@features/users/types/user';
export default { export default {
title: '@molecules/grouped-rows', title: '@molecules/grouped-rows',
}; };
const mockUser = (first_name: string, last_name: string, email: string, thumbnail?: string) : UserType =>
({
username: 'anonymous if this is empty',
first_name, last_name, email, thumbnail,
} as UserType);
const Template: ComponentStory<any> = (props: { const Template: ComponentStory<any> = (props: {
title: string; first_name: string;
subtitle: string; last_name: string;
email: string;
thumbnail?: string;
className: string;
checked: boolean; checked: boolean;
}) => { }) => {
return ( return (
<div className="flex"> <div className="flex">
<div className="w-96 border border-gray-300 rounded-sm px-2 m-2"> <div className="w-96 border border-gray-300 dark:border-zinc-600 rounded-sm m-2">
<UserBlock <UserBlock
avatar={ className="p-2"
<Avatar avatar="https://images.freeimages.com/images/small-previews/d67/experimenting-with-nature-1547377.jpg" /> user={mockUser("Romaric", "Mourgues", "r.mourgues@linagora.com", "https://images.freeimages.com/images/small-previews/d67/experimenting-with-nature-1547377.jpg")}
}
title="Romaric Mourgues"
subtitle="r.mourgues@linagora.com"
suffix={ suffix={
<div className="text-blue-500"> <div className="text-blue-500">
<CheckIcon fill="currentColor" /> <CheckIcon fill="currentColor" />
</div> </div>
} }
className="py-2 border-b border-gray-300"
/> />
<UserBlock <UserBlock
avatar={<Avatar title="Diana Potokina" />} className={props.className}
title="Diana Potokina" user={mockUser(props.first_name, props.last_name, props.email, props.thumbnail)}
subtitle="r.potokina@linagora.com"
className="py-2 border-b border-gray-300"
/>
<UserBlock
avatar={<Avatar title={props.title} />}
title={props.title}
subtitle={props.subtitle}
suffix={ suffix={
(props.checked && ( (props.checked && (
<div className="text-blue-500"> <div className="text-blue-500">
<CheckIcon fill="currentColor" /> <CheckIcon fill="currentColor" />
</div> </div>
)) || <></> ))
} }
className="py-2" />
<UserBlock
className="p-2 border-t border-gray-300 dark:border-zinc-600"
user={mockUser("Diana", "Potokina", "r.potokina@linagora.com")}
/> />
</div> </div>
</div> </div>
@@ -57,7 +57,10 @@ const Template: ComponentStory<any> = (props: {
export const User = Template.bind({}); export const User = Template.bind({});
User.args = { User.args = {
title: 'Another user', first_name: 'fred ✏️',
subtitle: 'Just a test user', last_name: 'ictitiuS editable',
email: "sampleemail@example.com",
className: "p-2 border-t border-gray-300 dark:border-zinc-600",
thumbnail: "",
checked: false, checked: false,
}; };
@@ -1,16 +1,43 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable @typescript-eslint/ban-ts-comment */
import React from 'react'; import React from 'react';
import { Base, Info } from '@atoms/text';
import Avatar from '@atoms/avatar';
import BaseBlock from '@molecules/grouped-rows/base'; import BaseBlock from '@molecules/grouped-rows/base';
import Languages from '@features/global/services/languages-service';
import type { UserType } from '@features/users/types/user';
import { getFullName } from '@features/users/utils/get-full-name';
// @ts-ignore interface UserBlockProps {
interface UserBlockProps extends React.InputHTMLAttributes<HTMLInputElement> {
avatar: JSX.Element;
title: JSX.Element | string;
subtitle: JSX.Element | string;
suffix?: JSX.Element | string;
className?: string; className?: string;
suffix?: JSX.Element | string | false;
title_suffix?: JSX.Element | string | false;
subtitle_suffix?: JSX.Element | string | false;
user?: UserType;
isSelf?: boolean;
} }
export default function UserBlock(props: UserBlockProps) { export default function UserBlock(props: UserBlockProps) {
return BaseBlock(props); return <BaseBlock
className={props.className}
suffix={props.suffix}
title_suffix={props.title_suffix}
subtitle_suffix={props.subtitle_suffix}
avatar={
<Avatar
avatar={props.user?.thumbnail || ''}
title={props.user ? getFullName(props.user) : '-'}
size="sm"
/>
}
title={
<>
<Base>{!!props.user && getFullName(props.user)}</Base>
{props.isSelf && <Info>{' ' + Languages.t('components.internal-access_specific_rules_you')}</Info>}
</>
}
subtitle={
<div className='text-sm text-slate-500'>{props.user?.email || ""}</div>
}
/>
} }