Skip to content

Commit ffe4431

Browse files
committed
feat: focused channel
1 parent 293e15e commit ffe4431

File tree

6 files changed

+107
-10
lines changed

6 files changed

+107
-10
lines changed

apps/backend/src/api/routes/posts.controller.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class PostsController {
3838
private _starsService: StarsService,
3939
private _messagesService: MessagesService,
4040
private _agentGraphService: AgentGraphService,
41-
private _shortLinkService: ShortLinkService,
41+
private _shortLinkService: ShortLinkService
4242
) {}
4343

4444
@Get('/:id/statistics')
@@ -111,6 +111,14 @@ export class PostsController {
111111
return { date: await this._postsService.findFreeDateTime(org.id) };
112112
}
113113

114+
@Get('/find-slot/:id')
115+
async findSlotIntegration(
116+
@GetOrgFromRequest() org: Organization,
117+
@Param('id') id?: string
118+
) {
119+
return { date: await this._postsService.findFreeDateTime(org.id, id) };
120+
}
121+
114122
@Get('/predict-trending')
115123
predictTrending() {
116124
return this._starsService.predictTrending();
@@ -183,7 +191,7 @@ export class PostsController {
183191
@Post('/separate-posts')
184192
async separatePosts(
185193
@GetOrgFromRequest() org: Organization,
186-
@Body() body: { content: string, len: number }
194+
@Body() body: { content: string; len: number }
187195
) {
188196
return this._postsService.separatePosts(body.content, body.len);
189197
}

apps/frontend/src/components/launches/menu/menu.tsx

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ import { useToaster } from '@gitroom/react/toaster/toaster';
1414
import interClass from '@gitroom/react/helpers/inter.font';
1515
import { useModals } from '@mantine/modals';
1616
import { TimeTable } from '@gitroom/frontend/components/launches/time.table';
17-
import { useCalendar } from '@gitroom/frontend/components/launches/calendar.context';
17+
import {
18+
Integrations,
19+
useCalendar,
20+
} from '@gitroom/frontend/components/launches/calendar.context';
1821
import { BotPicture } from '@gitroom/frontend/components/launches/bot.picture';
1922
import { CustomerModal } from '@gitroom/frontend/components/launches/customer.modal';
2023
import { Integration } from '@prisma/client';
2124
import { SettingsModal } from '@gitroom/frontend/components/launches/settings.modal';
2225
import { CustomVariables } from '@gitroom/frontend/components/launches/add.provider.component';
2326
import { useRouter } from 'next/navigation';
2427
import { useT } from '@gitroom/react/translation/get.transation.service.client';
28+
import { AddEditModal } from '@gitroom/frontend/components/new-launch/add.edit.modal';
29+
import dayjs from 'dayjs';
2530
export const Menu: FC<{
2631
canEnable: boolean;
2732
canDisable: boolean;
@@ -50,7 +55,7 @@ export const Menu: FC<{
5055

5156
const fetch = useFetch();
5257
const router = useRouter();
53-
const { integrations } = useCalendar();
58+
const { integrations, reloadCalendarView } = useCalendar();
5459
const toast = useToaster();
5560
const modal = useModals();
5661
const [show, setShow] = useState(false);
@@ -112,6 +117,7 @@ export const Menu: FC<{
112117
setShow(false);
113118
onChange(true);
114119
}, []);
120+
115121
const enableChannel = useCallback(async () => {
116122
await fetch('/integrations/enable', {
117123
method: 'POST',
@@ -123,6 +129,7 @@ export const Menu: FC<{
123129
setShow(false);
124130
onChange(false);
125131
}, []);
132+
126133
const editTimeTable = useCallback(() => {
127134
const findIntegration = integrations.find(
128135
(integration) => integration.id === id
@@ -139,6 +146,42 @@ export const Menu: FC<{
139146
});
140147
setShow(false);
141148
}, [integrations]);
149+
150+
const createPost = useCallback(
151+
(integration: Integrations) => async () => {
152+
setShow(false);
153+
154+
const { date } = await (
155+
await fetch(`/posts/find-slot/${integration.id}`)
156+
).json();
157+
158+
modal.openModal({
159+
closeOnClickOutside: false,
160+
closeOnEscape: false,
161+
withCloseButton: false,
162+
classNames: {
163+
modal: 'w-[100%] max-w-[1400px] bg-transparent text-textColor',
164+
},
165+
children: (
166+
<AddEditModal
167+
allIntegrations={integrations.map((p) => ({
168+
...p,
169+
}))}
170+
reopenModal={createPost(integration)}
171+
mutate={reloadCalendarView}
172+
integrations={integrations}
173+
selectedChannels={[integration.id]}
174+
focusedChannel={integration.id}
175+
date={dayjs.utc(date).local()}
176+
/>
177+
),
178+
size: '80%',
179+
title: ``,
180+
});
181+
},
182+
[integrations]
183+
);
184+
142185
const changeBotPicture = useCallback(() => {
143186
const findIntegration = integrations.find(
144187
(integration) => integration.id === id
@@ -251,6 +294,30 @@ export const Menu: FC<{
251294
onClick={(e) => e.stopPropagation()}
252295
className={`absolute top-[100%] start-0 p-[8px] px-[20px] bg-fifth flex flex-col gap-[16px] z-[100] rounded-[8px] border border-tableBorder ${interClass} text-nowrap`}
253296
>
297+
{canDisable && !findIntegration?.refreshNeeded && (
298+
<div
299+
className="flex gap-[12px] items-center"
300+
onClick={createPost(findIntegration!)}
301+
>
302+
<div>
303+
<svg
304+
xmlns="http://www.w3.org/2000/svg"
305+
width="18"
306+
height="18"
307+
viewBox="0 0 32 32"
308+
fill="none"
309+
>
310+
<path
311+
d="M21 4H11C9.14409 4.00199 7.36477 4.74012 6.05245 6.05245C4.74012 7.36477 4.00199 9.14409 4 11V21C4.00199 22.8559 4.74012 24.6352 6.05245 25.9476C7.36477 27.2599 9.14409 27.998 11 28H17C17.1075 27.9999 17.2142 27.9826 17.3162 27.9487C20.595 26.855 26.855 20.595 27.9487 17.3162C27.9826 17.2142 27.9999 17.1075 28 17V11C27.998 9.14409 27.2599 7.36477 25.9476 6.05245C24.6352 4.74012 22.8559 4.00199 21 4ZM17 25.9275V22C17 20.6739 17.5268 19.4021 18.4645 18.4645C19.4021 17.5268 20.6739 17 22 17H25.9275C24.77 19.6938 19.6938 24.77 17 25.9275Z"
312+
fill="green"
313+
/>
314+
</svg>
315+
</div>
316+
<div className="text-[12px]">
317+
{t('create_new_post', 'Create a new post')}
318+
</div>
319+
</div>
320+
)}
254321
{canDisable &&
255322
findIntegration?.refreshNeeded &&
256323
!findIntegration.customFields && (

apps/frontend/src/components/new-launch/add.edit.modal.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export interface AddEditModalProps {
1414
date: dayjs.Dayjs;
1515
integrations: Integrations[];
1616
allIntegrations?: Integrations[];
17+
selectedChannels?: string[];
1718
set?: CreatePostDto;
19+
focusedChannel?: string;
1820
addEditSets?: (data: any) => void;
1921
reopenModal: () => void;
2022
mutate: () => void;
@@ -82,6 +84,15 @@ export const AddEditModalInner: FC<AddEditModalProps> = (props) => {
8284
);
8385
addOrRemoveSelectedIntegration(integration, existingData.settings);
8486
}
87+
88+
if (props?.selectedChannels?.length) {
89+
for (const channel of props.selectedChannels) {
90+
const integration = integrations.find((i) => i.id === channel);
91+
if (integration) {
92+
addOrRemoveSelectedIntegration(integration, {});
93+
}
94+
}
95+
}
8596
}, []);
8697

8798
if (existingData.integration && selectedIntegrations.length === 0) {
@@ -135,6 +146,10 @@ export const AddEditModalInnerInner: FC<AddEditModalProps> = (props) => {
135146
setCurrent(existingData.integration);
136147
}
137148

149+
if (props.focusedChannel) {
150+
setCurrent(props.focusedChannel);
151+
}
152+
138153
addGlobalValue(
139154
0,
140155
props.onlyValues?.length

libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,10 @@ export class IntegrationRepository {
549549
});
550550
}
551551

552-
async getPostingTimes(orgId: string) {
552+
async getPostingTimes(orgId: string, integrationsId?: string) {
553553
return this._integration.model.integration.findMany({
554554
where: {
555+
...(integrationsId ? { id: integrationsId } : {}),
555556
organizationId: orgId,
556557
disabled: false,
557558
deletedAt: null,

libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class IntegrationService {
3333
private _autopostsRepository: AutopostRepository,
3434
private _integrationManager: IntegrationManager,
3535
private _notificationService: NotificationService,
36-
private _workerServiceProducer: BullMqClient,
36+
private _workerServiceProducer: BullMqClient
3737
) {}
3838

3939
async changeActiveCron(orgId: string) {
@@ -673,8 +673,14 @@ export class IntegrationService {
673673
return difference(id, loadOnlyIds);
674674
}
675675

676-
async findFreeDateTime(orgId: string): Promise<number[]> {
677-
const findTimes = await this._integrationRepository.getPostingTimes(orgId);
676+
async findFreeDateTime(
677+
orgId: string,
678+
integrationsId?: string
679+
): Promise<number[]> {
680+
const findTimes = await this._integrationRepository.getPostingTimes(
681+
orgId,
682+
integrationsId
683+
);
678684
return uniq(
679685
findTimes.reduce((all: any, current: any) => {
680686
return [

libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,8 @@ export class PostsService {
928928
return this._postRepository.findPopularPosts(category, topic);
929929
}
930930

931-
async findFreeDateTime(orgId: string) {
932-
const findTimes = await this._integrationService.findFreeDateTime(orgId);
931+
async findFreeDateTime(orgId: string, integrationId?: string) {
932+
const findTimes = await this._integrationService.findFreeDateTime(orgId, integrationId);
933933
return this.findFreeDateTimeRecursive(
934934
orgId,
935935
findTimes,

0 commit comments

Comments
 (0)