-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Trompette
committed
Jan 24, 2024
1 parent
0063d3e
commit dd68e85
Showing
8 changed files
with
193 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/twenty-front/src/modules/activities/emails/hooks/useThread.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useRecoilState, useResetRecoilState } from 'recoil'; | ||
|
||
import { MockedThread } from '@/activities/emails/mocks/mockedThreads'; | ||
import { useOpenThreadRightDrawer } from '@/activities/emails/right-drawer/hooks/useOpenThreadRightDrawer'; | ||
import { viewableMessageThreadIdsFamilyState } from '@/activities/emails/state/viewableMessageThreadIdsFamilyState'; | ||
import { viewableThreadState } from '@/activities/emails/state/viewableThreadState'; | ||
|
||
export const useThread = () => { | ||
const [viewableThread, setViewableThread] = | ||
useRecoilState(viewableThreadState); | ||
|
||
const resetViewableMessageThread = useResetRecoilState( | ||
viewableMessageThreadIdsFamilyState(viewableThread?.id ?? ''), | ||
); | ||
|
||
const openThredRightDrawer = useOpenThreadRightDrawer(); | ||
|
||
const openThread = (thread: MockedThread) => { | ||
if (viewableThread?.id !== thread.id) { | ||
resetViewableMessageThread(); | ||
} | ||
|
||
openThredRightDrawer(); | ||
|
||
setViewableThread(thread); | ||
}; | ||
|
||
return { | ||
openThread, | ||
}; | ||
}; |
110 changes: 110 additions & 0 deletions
110
packages/twenty-front/src/modules/activities/emails/mocks/mockedThreads.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { DateTime } from 'luxon'; | ||
|
||
import { Scalars, TimelineThread } from '~/generated/graphql'; | ||
|
||
export type MockedThread = { | ||
id: string; | ||
} & TimelineThread; | ||
|
||
export type MockedEmailUser = { | ||
avatarUrl: string; | ||
displayName: string; | ||
workspaceMemberId?: string; | ||
personId?: string; | ||
}; | ||
|
||
export type MockedMessage = { | ||
id: string; | ||
from: MockedEmailUser; | ||
to: MockedEmailUser[]; | ||
subject: string; | ||
body: string; | ||
sentAt: string; | ||
}; | ||
|
||
export const mockedThreads: MockedThread[] = [ | ||
{ | ||
__typename: 'TimelineThread', | ||
id: '1', | ||
body: 'This is a test email' as Scalars['String'], | ||
numberOfMessagesInThread: 5 as Scalars['Float'], | ||
read: true as Scalars['Boolean'], | ||
receivedAt: new Date().toISOString() as Scalars['DateTime'], | ||
senderName: 'Thom Trp' as Scalars['String'], | ||
senderPictureUrl: '' as Scalars['String'], | ||
subject: 'Test email' as Scalars['String'], | ||
}, | ||
{ | ||
__typename: 'TimelineThread', | ||
id: '2', | ||
body: 'This is a second test email' as Scalars['String'], | ||
numberOfMessagesInThread: 5 as Scalars['Float'], | ||
read: true as Scalars['Boolean'], | ||
receivedAt: new Date().toISOString() as Scalars['DateTime'], | ||
senderName: 'Coco Den' as Scalars['String'], | ||
senderPictureUrl: '' as Scalars['String'], | ||
subject: 'Test email number 2' as Scalars['String'], | ||
}, | ||
]; | ||
|
||
export const mockedMessagesByThread: Map<string, MockedMessage[]> = new Map([ | ||
[ | ||
'1', | ||
Array.from({ length: 5 }).map((_, i) => ({ | ||
id: `id${i + 1}`, | ||
from: { | ||
avatarUrl: '', | ||
displayName: `User ${i + 1}`, | ||
workspaceMemberId: `workspaceMemberId${i + 1}`, | ||
personId: `personId${i + 1}`, | ||
}, | ||
to: [ | ||
{ | ||
avatarUrl: 'https://favicon.twenty.com/qonto.com', | ||
displayName: `User ${i + 2}`, | ||
workspaceMemberId: `workspaceMemberId${i + 1}`, | ||
personId: `personId${i + 2}`, | ||
}, | ||
], | ||
subject: `Subject ${i + 1}`, | ||
body: `Body ${ | ||
i + 1 | ||
}. I am testing a very long body. I am adding more text. | ||
I also want to test a new line. To see if it works. | ||
I am adding a new paragraph. | ||
Thomas`, | ||
sentAt: DateTime.fromFormat('2021-03-12', 'yyyy-MM-dd').toISO() ?? '', | ||
})), | ||
], | ||
[ | ||
'2', | ||
Array.from({ length: 5 }).map((_, i) => ({ | ||
id: `id${i + 10}`, | ||
from: { | ||
avatarUrl: '', | ||
displayName: `Other user ${i + 1}`, | ||
workspaceMemberId: `workspaceMemberId${i + 1}`, | ||
personId: `personId${i + 1}`, | ||
}, | ||
to: [ | ||
{ | ||
avatarUrl: 'https://favicon.twenty.com/qonto.com', | ||
displayName: `Other user ${i + 2}`, | ||
workspaceMemberId: `workspaceMemberId${i + 1}`, | ||
personId: `personId${i + 2}`, | ||
}, | ||
], | ||
subject: `Subject ${i + 1}`, | ||
body: `Body ${ | ||
i + 1 | ||
}. Hello, I am testing a very long body. I am adding more text. | ||
I am adding a new paragraph. | ||
Thomas`, | ||
sentAt: DateTime.fromFormat('2021-03-12', 'yyyy-MM-dd').toISO() ?? '', | ||
})), | ||
], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/twenty-front/src/modules/activities/emails/state/viewableThreadState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { atom } from 'recoil'; | ||
|
||
import { MockedThread } from '@/activities/emails/mocks/mockedThreads'; | ||
|
||
export const viewableThreadState = atom<MockedThread | null>({ | ||
key: 'viewableThreadState', | ||
default: null, | ||
}); |