The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Rework website TasksVisual to match twenty-front tasks tab (#22143)
Abdullah.551a7922912f
diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.test.tsx b/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.test.tsxnew file mode 100644index 00000000000..cfa8c50bdfb--- /dev/null+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.test.tsx@@ -0,0 +1,93 @@+import { i18n } from '@lingui/core';+import { I18nProvider } from '@lingui/react';+import { render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';++import { TasksVisual } from './TasksVisual';++i18n.load('en', {});+i18n.activate('en');++function renderVisual() {+ return render(+ <I18nProvider i18n={i18n}>+ <TasksVisual active />+ </I18nProvider>,+ );+}++describe('TasksVisual', () => {+ it('renders each task with its body and due date', () => {+ renderVisual();++ expect(screen.getByText('Send NDA')).toBeInTheDocument();+ expect(+ screen.getByText('Loop in legal before sending.'),+ ).toBeInTheDocument();+ expect(screen.getByText('Jul 22, 2026')).toBeInTheDocument();+ });++ it('renders the completed task alongside the open ones', () => {+ renderVisual();++ expect(screen.getByText('Prepare onboarding deck')).toBeInTheDocument();+ expect(screen.getByText('Schedule security review')).toBeInTheDocument();+ });++ it('assigns every task to Félix Malfait', () => {+ renderVisual();++ expect(screen.getAllByText('Félix Malfait')).toHaveLength(4);+ });++ it('offers an add-task action', () => {+ renderVisual();++ expect(screen.getByText('Add task')).toBeInTheDocument();+ });++ it('completes a task when its checkbox is clicked', async () => {+ const user = userEvent.setup();+ renderVisual();++ const checkbox = screen.getByRole('checkbox', { name: 'Send NDA' });+ expect(checkbox).toHaveAttribute('aria-checked', 'false');++ await user.click(checkbox);++ expect(screen.getByRole('checkbox', { name: 'Send NDA' })).toHaveAttribute(+ 'aria-checked',+ 'true',+ );+ });++ it('completes a task with the keyboard', async () => {+ const user = userEvent.setup();+ renderVisual();++ const checkbox = screen.getByRole('checkbox', {+ name: 'Follow up on pricing',+ });+ checkbox.focus();+ await user.keyboard(' ');++ expect(+ screen.getByRole('checkbox', { name: 'Follow up on pricing' }),+ ).toHaveAttribute('aria-checked', 'true');+ });++ it('removes the add-task button instead of moving it to Done when every task is done', async () => {+ const user = userEvent.setup();+ renderVisual();++ await user.click(screen.getByRole('checkbox', { name: 'Send NDA' }));+ await user.click(+ screen.getByRole('checkbox', { name: 'Follow up on pricing' }),+ );+ await user.click(+ screen.getByRole('checkbox', { name: 'Prepare onboarding deck' }),+ );++ expect(screen.queryByText('Add task')).not.toBeInTheDocument();+ });+});diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.tsx b/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.tsxindex 65192821b64..0ded0dc2b26 100644--- a/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.tsx+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/TasksVisual.tsx@@ -1,13 +1,18 @@'use client';+import { msg } from '@lingui/core/macro';+import { useLingui } from '@lingui/react';import { styled } from '@linaria/react';+import { useState } from 'react';import { THEME_LIGHT } from 'twenty-ui/theme';import { previewFontSize } from '@/app-preview/preview-font-size';import { RecordTabHeader } from '../components/RecordTabHeader';+import { AddTaskButton } from './components/AddTaskButton';import { TaskRow } from './components/TaskRow';-import { TASK_GROUPS } from './data/task-groups';+import { TASKS } from './data/tasks';+import { toggleTaskDone } from './utils/toggle-task-done';const Root = styled.div`background-color: ${THEME_LIGHT.background.primary};@@ -31,43 +36,73 @@ const Panel = styled.div`const Group = styled.div`display: flex;flex-direction: column;-- & + & {- margin-top: 8px;- }+ padding: 0 16px;`;const GroupHeader = styled.div`align-items: center;- color: ${THEME_LIGHT.font.color.light};+ color: ${THEME_LIGHT.font.color.primary};display: flex;- font-size: ${previewFontSize(THEME_LIGHT.font.size.sm)};+ font-size: ${previewFontSize(THEME_LIGHT.font.size.md)};font-weight: ${THEME_LIGHT.font.weight.semiBold};- gap: 6px;- padding: 0 16px 4px;+ justify-content: space-between;+ margin: ${THEME_LIGHT.spacing(4)} 0;`;const GroupCount = styled.span`- color: ${THEME_LIGHT.font.color.tertiary};- font-weight: ${THEME_LIGHT.font.weight.medium};+ color: ${THEME_LIGHT.font.color.light};+ margin-left: ${THEME_LIGHT.spacing(2)};+`;++const GroupCard = styled.div`+ border: 1px solid ${THEME_LIGHT.border.color.medium};+ border-radius: ${THEME_LIGHT.border.radius.sm};+ overflow: hidden;++ & > * + * {+ border-top: 1px solid ${THEME_LIGHT.border.color.light};+ }`;export function TasksVisual({ active: _active }: { active: boolean }) {+ const { i18n } = useLingui();+ const [tasks, setTasks] = useState(TASKS);++ const handleToggle = (id: string) => {+ setTasks((previous) => toggleTaskDone(previous, id));+ };++ const groups = [+ { id: 'todo', items: tasks.filter((task) => !task.done), label: msg`TODO` },+ { id: 'done', items: tasks.filter((task) => task.done), label: msg`DONE` },+ ];+return (<Root><RecordTabHeader active="Tasks" /><Panel>- {TASK_GROUPS.map((group) => (- <Group key={group.label}>- <GroupHeader>- {group.label}- <GroupCount>{group.items.length}</GroupCount>- </GroupHeader>- {group.items.map((task) => (- <TaskRow key={task.title} task={task} />- ))}- </Group>- ))}+ {groups.map((group) =>+ group.items.length > 0 ? (+ <Group key={group.id}>+ <GroupHeader>+ <span>+ {i18n._(group.label)}+ <GroupCount>{group.items.length}</GroupCount>+ </span>+ {group.id === 'todo' && <AddTaskButton />}+ </GroupHeader>+ <GroupCard>+ {group.items.map((task) => (+ <TaskRow+ key={task.id}+ onToggle={() => handleToggle(task.id)}+ task={task}+ />+ ))}+ </GroupCard>+ </Group>+ ) : null,+ )}</Panel></Root>);diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/components/AddTaskButton.test.tsx b/packages/twenty-website/src/sections/product-feature/TasksVisual/components/AddTaskButton.test.tsxnew file mode 100644index 00000000000..6aef165e7cb--- /dev/null+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/components/AddTaskButton.test.tsx@@ -0,0 +1,20 @@+import { i18n } from '@lingui/core';+import { I18nProvider } from '@lingui/react';+import { render, screen } from '@testing-library/react';++import { AddTaskButton } from './AddTaskButton';++i18n.load('en', {});+i18n.activate('en');++describe('AddTaskButton', () => {+ it('renders the add-task label', () => {+ render(+ <I18nProvider i18n={i18n}>+ <AddTaskButton />+ </I18nProvider>,+ );++ expect(screen.getByText('Add task')).toBeInTheDocument();+ });+});diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/components/AddTaskButton.tsx b/packages/twenty-website/src/sections/product-feature/TasksVisual/components/AddTaskButton.tsxnew file mode 100644index 00000000000..eb55ac6bc51--- /dev/null+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/components/AddTaskButton.tsx@@ -0,0 +1,36 @@+'use client';++import { msg } from '@lingui/core/macro';+import { useLingui } from '@lingui/react';+import { styled } from '@linaria/react';+import { IconPlus } from '@tabler/icons-react';+import { THEME_LIGHT } from 'twenty-ui/theme';++import { previewFontSize } from '@/app-preview/preview-font-size';++const Button = styled.div`+ align-items: center;+ background-color: transparent;+ border: 1px solid ${THEME_LIGHT.background.transparent.medium};+ border-radius: ${THEME_LIGHT.border.radius.sm};+ box-sizing: border-box;+ color: ${THEME_LIGHT.font.color.secondary};+ display: inline-flex;+ flex-shrink: 0;+ font-size: ${previewFontSize(THEME_LIGHT.font.size.md)};+ font-weight: ${THEME_LIGHT.font.weight.medium};+ gap: ${THEME_LIGHT.spacing(1)};+ height: 24px;+ padding: 0 ${THEME_LIGHT.spacing(2)};+ white-space: nowrap;+`;++export function AddTaskButton() {+ const { i18n } = useLingui();+ return (+ <Button>+ <IconPlus size={14} stroke={2} />+ {i18n._(msg`Add task`)}+ </Button>+ );+}diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/components/TaskRow.tsx b/packages/twenty-website/src/sections/product-feature/TasksVisual/components/TaskRow.tsxindex 52f5a9bc22c..e6db340dd4f 100644--- a/packages/twenty-website/src/sections/product-feature/TasksVisual/components/TaskRow.tsx+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/components/TaskRow.tsx@@ -1,3 +1,6 @@+'use client';++import { useLingui } from '@lingui/react';import { styled } from '@linaria/react';import { IconCalendar, IconCheck } from '@tabler/icons-react';import { THEME_LIGHT } from 'twenty-ui/theme';@@ -10,14 +13,16 @@ import { type Task } from '../types/task';const Row = styled.div`align-items: center;+ background-color: ${THEME_LIGHT.background.secondary};box-sizing: border-box;+ cursor: pointer;display: flex;gap: 8px;height: 48px;padding: 0 16px;&:hover {- background-color: ${THEME_LIGHT.background.transparent.light};+ background-color: transparent;}`;@@ -29,14 +34,30 @@ const RowLeft = styled.div`overflow: hidden;`;+const CheckboxButton = styled.span`+ align-items: center;+ border-radius: ${THEME_LIGHT.border.radius.rounded};+ display: inline-flex;+ flex-shrink: 0;+ justify-content: center;+ padding: 5px;++ &:hover {+ background-color: ${THEME_LIGHT.background.transparent.light};+ }++ &[data-done]:hover {+ background-color: ${THEME_LIGHT.background.transparent.blue};+ }+`;+const Checkbox = styled.span`align-items: center;- border: 1px solid ${THEME_LIGHT.border.color.strong};+ border: 1px solid ${THEME_LIGHT.border.color.inverted};border-radius: ${THEME_LIGHT.border.radius.rounded};box-sizing: border-box;color: ${THEME_LIGHT.font.color.inverted};display: flex;- flex-shrink: 0;height: 14px;justify-content: center;width: 14px;@@ -88,15 +109,40 @@ const Due = styled.span`white-space: nowrap;`;-export function TaskRow({ task }: { task: Task }) {+export function TaskRow({+ task,+ onToggle,+}: {+ task: Task;+ onToggle: () => void;+}) {+ const { i18n } = useLingui();+ const title = i18n._(task.title);+ const doneFlag = task.done ? '' : undefined;+return (<Row><RowLeft>- <Checkbox data-done={task.done ? '' : undefined}>- {task.done ? <IconCheck size={11} stroke={2.5} /> : null}- </Checkbox>- <Title data-done={task.done ? '' : undefined}>{task.title}</Title>- <Body>{task.body}</Body>+ <CheckboxButton+ aria-checked={task.done}+ aria-label={title}+ data-done={doneFlag}+ onClick={onToggle}+ onKeyDown={(event) => {+ if (event.key === 'Enter' || event.key === ' ') {+ event.preventDefault();+ onToggle();+ }+ }}+ role="checkbox"+ tabIndex={0}+ >+ <Checkbox data-done={doneFlag}>+ {task.done ? <IconCheck size={11} stroke={2.5} /> : null}+ </Checkbox>+ </CheckboxButton>+ <Title data-done={doneFlag}>{title}</Title>+ <Body>{i18n._(task.body)}</Body></RowLeft><RowRight><Due>@@ -113,7 +159,7 @@ export function TaskRow({ task }: { task: Task }) {}}/>}- variant="transparent"+ variant="highlighted"/></RowRight></Row>diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/data/task-groups.ts b/packages/twenty-website/src/sections/product-feature/TasksVisual/data/task-groups.tsdeleted file mode 100644index 503804ecb9b..00000000000--- a/packages/twenty-website/src/sections/product-feature/TasksVisual/data/task-groups.ts+++ /dev/null@@ -1,7 +0,0 @@-import { type Task } from '../types/task';-import { TASKS } from './tasks';--export const TASK_GROUPS: { items: Task[]; label: string }[] = [- { items: TASKS.filter((task) => !task.done), label: 'To do' },- { items: TASKS.filter((task) => task.done), label: 'Done' },-];diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/data/tasks.ts b/packages/twenty-website/src/sections/product-feature/TasksVisual/data/tasks.tsindex ebb1dcf6379..6a07eda4d14 100644--- a/packages/twenty-website/src/sections/product-feature/TasksVisual/data/tasks.ts+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/data/tasks.ts@@ -1,3 +1,5 @@+import { msg } from '@lingui/core/macro';+import { sharedAssetUrls } from '@/app-preview/data/shared-asset-urls';import { type Task } from '../types/task';@@ -6,31 +8,35 @@ const PEOPLE = sharedAssetUrls.peopleAvatars;export const TASKS: Task[] = [{- body: 'Loop in legal before sending.',+ body: msg`Loop in legal before sending.`,done: false,- due: 'Tomorrow',- target: { avatarUrl: PEOPLE.darioAmodei, name: 'Dario Amodei' },- title: 'Send NDA',+ due: 'Jul 22, 2026',+ id: 'send-nda',+ target: { avatarUrl: PEOPLE.anonymousFelix, name: 'Félix Malfait' },+ title: msg`Send NDA`,},{- body: 'Send the updated annual quote.',+ body: msg`Send the updated annual quote.`,done: false,- due: 'Jul 24',- target: { avatarUrl: PEOPLE.patrickCollison, name: 'Patrick Collison' },- title: 'Follow up on pricing',+ due: 'Jul 24, 2026',+ id: 'follow-up-pricing',+ target: { avatarUrl: PEOPLE.anonymousFelix, name: 'Félix Malfait' },+ title: msg`Follow up on pricing`,},{- body: 'Use the Q3 template.',+ body: msg`Use the Q3 template.`,done: false,- due: 'Jul 26',- target: { avatarUrl: PEOPLE.dylanField, name: 'Dylan Field' },- title: 'Onboarding deck',+ due: 'Jul 26, 2026',+ id: 'prepare-onboarding-deck',+ target: { avatarUrl: PEOPLE.anonymousFelix, name: 'Félix Malfait' },+ title: msg`Prepare onboarding deck`,},{- body: 'Coordinated with the data team.',+ body: msg`Coordinated with the IT team.`,done: true,- due: 'Jul 18',- target: { avatarUrl: PEOPLE.darioAmodei, name: 'Dario Amodei' },- title: 'Schedule security review',+ due: 'Jul 18, 2026',+ id: 'schedule-security-review',+ target: { avatarUrl: PEOPLE.anonymousFelix, name: 'Félix Malfait' },+ title: msg`Schedule security review`,},];diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/types/task.ts b/packages/twenty-website/src/sections/product-feature/TasksVisual/types/task.tsindex 91eaa95fcac..4781b55ced3 100644--- a/packages/twenty-website/src/sections/product-feature/TasksVisual/types/task.ts+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/types/task.ts@@ -1,12 +1,15 @@+import { type MessageDescriptor } from '@lingui/core';+type TaskTarget = {avatarUrl: string;name: string;};export type Task = {- body: string;+ body: MessageDescriptor;done: boolean;due: string;+ id: string;target: TaskTarget;- title: string;+ title: MessageDescriptor;};diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/utils/toggle-task-done.test.ts b/packages/twenty-website/src/sections/product-feature/TasksVisual/utils/toggle-task-done.test.tsnew file mode 100644index 00000000000..c98f5927146--- /dev/null+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/utils/toggle-task-done.test.ts@@ -0,0 +1,40 @@+import { type Task } from '../types/task';+import { toggleTaskDone } from './toggle-task-done';++const TASKS: Task[] = [+ {+ body: { id: 'a' },+ done: false,+ due: '',+ id: 'a',+ target: { avatarUrl: '', name: '' },+ title: { id: 'a' },+ },+ {+ body: { id: 'b' },+ done: true,+ due: '',+ id: 'b',+ target: { avatarUrl: '', name: '' },+ title: { id: 'b' },+ },+];++describe('toggleTaskDone', () => {+ it('should mark a not-done task as done', () => {+ expect(toggleTaskDone(TASKS, 'a')[0].done).toBe(true);+ });++ it('should mark a done task as not done', () => {+ expect(toggleTaskDone(TASKS, 'b')[1].done).toBe(false);+ });++ it('should leave the other tasks untouched', () => {+ expect(toggleTaskDone(TASKS, 'a')[1]).toBe(TASKS[1]);+ });++ it('should not mutate the input tasks', () => {+ toggleTaskDone(TASKS, 'a');+ expect(TASKS[0].done).toBe(false);+ });+});diff --git a/packages/twenty-website/src/sections/product-feature/TasksVisual/utils/toggle-task-done.ts b/packages/twenty-website/src/sections/product-feature/TasksVisual/utils/toggle-task-done.tsnew file mode 100644index 00000000000..d598d6a0c6f--- /dev/null+++ b/packages/twenty-website/src/sections/product-feature/TasksVisual/utils/toggle-task-done.ts@@ -0,0 +1,7 @@+import { type Task } from '../types/task';++export function toggleTaskDone(tasks: Task[], id: string): Task[] {+ return tasks.map((task) =>+ task.id === id ? { ...task, done: !task.done } : task,+ );+}