π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: protected reposting post when clicking update
Nevo David2813ed01f9c7
diff --git a/apps/backend/src/api/routes/posts.controller.ts b/apps/backend/src/api/routes/posts.controller.tsindex ce03df002..69be508dc 100644--- a/apps/backend/src/api/routes/posts.controller.ts+++ b/apps/backend/src/api/routes/posts.controller.ts@@ -171,9 +171,10 @@ export class PostsController {changeDate(@GetOrgFromRequest() org: Organization,@Param('id') id: string,- @Body('date') date: string+ @Body('date') date: string,+ @Body('action') action: 'schedule' | 'update' = 'schedule') {- return this._postsService.changeDate(org.id, id, date);+ return this._postsService.changeDate(org.id, id, date, action);}@Post('/separate-posts')diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsxindex 3d08ddd7b..9dbd8e421 100644--- a/apps/frontend/src/components/launches/calendar.tsx+++ b/apps/frontend/src/components/launches/calendar.tsx@@ -54,6 +54,7 @@ import { deleteDialog } from '@gitroom/react/helpers/delete.dialog';import { useVariables } from '@gitroom/react/helpers/variable.context';import { stripHtmlValidation } from '@gitroom/helpers/utils/strip.html.validation';import { newDayjs } from '@gitroom/frontend/components/layout/set.timezone';+import { Button } from '@gitroom/react/form/button';// Extend dayjs with necessary pluginsextend(isSameOrAfter);@@ -418,6 +419,68 @@ export const CalendarColumn: FC<{accept: 'post',drop: async (item: any) => {if (isBeforeNow) return;++ // Find the post to check its state+ const post = posts.find((p) => p.id === item.id);+ let action: 'schedule' | 'update' = 'schedule';++ // Check if post is already published or queued in the past+ if (+ post &&+ (post.state === 'PUBLISHED' ||+ (post.state === 'QUEUE' && dayjs().isAfter(dayjs.utc(post.publishDate))))+ ) {+ const whatToDo = await new Promise<'schedule' | 'update' | 'cancel'>(+ (resolve) => {+ modal.openModal({+ title: t('what_do_you_want_to_do', 'What do you want to do?'),+ children: (+ <div className="flex flex-col">+ <div className="text-[20px] mb-[20px]">+ {t(+ 'post_already_published_drag',+ 'This post was already published, what do you want to do?'+ )}+ </div>+ <div className="flex w-full gap-[10px]">+ <div className="flex-1 flex">+ <Button+ type="button"+ className="flex-1"+ onClick={() => {+ modal.closeAll();+ resolve('update');+ }}+ >+ {t('just_update_post_details', 'Just update the post details')}+ </Button>+ </div>+ <div className="flex-1 flex">+ <Button+ type="button"+ className="flex-1"+ onClick={() => {+ modal.closeAll();+ resolve('schedule');+ }}+ >+ {t('reschedule_post', 'Reschedule the post')}+ </Button>+ </div>+ </div>+ </div>+ ),+ onClose: () => resolve('cancel'),+ });+ }+ );++ if (whatToDo === 'cancel') {+ return;+ }+ action = whatToDo;+ }+if (!item.interval) {changeDate(item.id, getDate);}@@ -425,10 +488,11 @@ export const CalendarColumn: FC<{method: 'PUT',body: JSON.stringify({date: getDate.utc().format('YYYY-MM-DDTHH:mm:ss'),+ action,}),});if (status !== 500) {- if (item.interval) {+ if (item.interval || action === 'schedule') {reloadCalendarView();return;}@@ -438,7 +502,7 @@ export const CalendarColumn: FC<{collect: (monitor) => ({canDrop: isBeforeNow ? false : !!monitor.canDrop() && !!monitor.isOver(),}),- }));+ }), [posts]);const editPost = useCallback((diff --git a/apps/frontend/src/components/new-launch/manage.modal.tsx b/apps/frontend/src/components/new-launch/manage.modal.tsxindex 8d1f9708e..d7cf56260 100644--- a/apps/frontend/src/components/new-launch/manage.modal.tsx+++ b/apps/frontend/src/components/new-launch/manage.modal.tsx@@ -42,6 +42,8 @@ import {} from '@gitroom/frontend/components/ui/icons';import { useHasScroll } from '@gitroom/frontend/components/ui/is.scroll.hook';import { useShortlinkPreference } from '@gitroom/frontend/components/settings/shortlink-preference.component';+import dayjs from 'dayjs';+import { Button } from '@gitroom/react/form/button';function countCharacters(text: string, type: string): number {if (type !== 'x') {@@ -108,14 +110,9 @@ export const ManageModal: FC<AddEditModalProps> = (props) => {return (<div className="flex items-center gap-[10px]"><div className="relative">- <SettingsIcon- size={15}- className="text-white"- />- </div>- <div>- Settings+ <SettingsIcon size={15} className="text-white" /></div>+ <div>Settings</div></div>);}@@ -202,7 +199,51 @@ export const ManageModal: FC<AddEditModalProps> = (props) => {}, [existingData, mutate, modal]);const schedule = useCallback(- (type: 'draft' | 'now' | 'schedule') => async () => {+ (type: 'draft' | 'now' | 'schedule' | 'update') => async () => {+ if (+ (type === 'now' || type === 'schedule') &&+ (existingData?.posts?.[0]?.state === 'PUBLISHED' ||+ (existingData?.posts?.[0]?.state === 'QUEUE' &&+ dayjs().isAfter(date.utc())))+ ) {+ const whatToDo = await new Promise((resolve) => {+ modal.openModal({+ title: 'What do you want to do?',+ children: (+ <div className="flex flex-col">+ <div className="text-[20px] mb-[20px]">+ This post was already published, what do you want to do?+ </div>+ <div className="flex w-full gap-[10px]">+ <div className="flex-1 flex">+ <Button+ type="button"+ className="flex-1"+ onClick={() => resolve('update')}+ >+ Just update the post details+ </Button>+ </div>+ <div className="flex-1 flex">+ <Button+ type="button"+ className="flex-1"+ onClick={() => resolve('republish')}+ >+ Republish the post+ </Button>+ </div>+ </div>+ </div>+ ),+ });+ });++ if (whatToDo === 'update') {+ type = 'update';+ }+ }+setLoading(true);const checkAllValid = await ref.current.checkAllValid();if (type !== 'draft') {@@ -476,10 +517,11 @@ export const ManageModal: FC<AddEditModalProps> = (props) => {'text-[14px] text-textColor font-[500] relative')}>- <div- className="absolute left-0 top-0 w-full h-full flex flex-col overflow-x-hidden overflow-y-auto scrollbar scrollbar-thumb-newBgColorInner scrollbar-track-newColColor"- >- <div id="social-settings" className="flex flex-col gap-[20px] bg-newBgColor" />+ <div className="absolute left-0 top-0 w-full h-full flex flex-col overflow-x-hidden overflow-y-auto scrollbar scrollbar-thumb-newBgColorInner scrollbar-track-newColColor">+ <div+ id="social-settings"+ className="flex flex-col gap-[20px] bg-newBgColor"+ /></div></div><style>diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.tsindex 04490afc1..3041f1d10 100644--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts@@ -330,15 +330,29 @@ export class PostsRepository {return update;}- async changeDate(orgId: string, id: string, date: string, isDraft: boolean) {+ async changeDate(+ orgId: string,+ id: string,+ date: string,+ isDraft: boolean,+ action: 'schedule' | 'update' = 'schedule'+ ) {return this._post.model.post.update({where: {organizationId: orgId,id,},data: {- state: isDraft ? 'DRAFT' : 'QUEUE',publishDate: dayjs(date).toDate(),+ // schedule: set state to QUEUE (or DRAFT if it was a draft)+ // update: don't change the state+ ...(action === 'schedule'+ ? {+ state: isDraft ? 'DRAFT' : 'QUEUE',+ releaseId: null,+ releaseURL: null,+ }+ : {}),},});}@@ -366,7 +380,7 @@ export class PostsRepository {}async createOrUpdatePost(- state: 'draft' | 'schedule' | 'now',+ state: 'draft' | 'schedule' | 'now' | 'update',orgId: string,date: string,body: PostBody,@@ -405,7 +419,12 @@ export class PostsRepository {group: uuid,intervalInDays: inter ? +inter : null,approvedSubmitForOrder: APPROVED_SUBMIT_FOR_ORDER.NO,- state: state === 'draft' ? ('DRAFT' as const) : ('QUEUE' as const),+ ...(state === 'update'+ ? {}+ : {+ state:+ state === 'draft' ? ('DRAFT' as const) : ('QUEUE' as const),+ }),image: JSON.stringify(value.image),settings: JSON.stringify(body.settings),organization: {diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.tsindex 5ed3feb49..207e815b9 100644--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts@@ -627,12 +627,14 @@ export class PostsService {return [] as any[];}- this.startWorkflow(- post.settings.__type.split('-')[0].toLowerCase(),- posts[0].id,- orgId,- posts[0].state- ).catch((err) => {});+ if (body.type !== 'update') {+ this.startWorkflow(+ post.settings.__type.split('-')[0].toLowerCase(),+ posts[0].id,+ orgId,+ posts[0].state+ ).catch((err) => {});+ }Sentry.metrics.count('post_created', 1);postList.push({@@ -652,23 +654,34 @@ export class PostsService {return this._postRepository.changeState(id, state, err, body);}- async changeDate(orgId: string, id: string, date: string) {+ async changeDate(+ orgId: string,+ id: string,+ date: string,+ action: 'schedule' | 'update' = 'schedule'+ ) {const getPostById = await this._postRepository.getPostById(id, orgId);++ // schedule: Set status to QUEUE and change date (reschedule the post)+ // update: Just change the date without changing the statusconst newDate = await this._postRepository.changeDate(orgId,id,date,- getPostById.state === 'DRAFT'+ getPostById.state === 'DRAFT',+ action);- try {- await this.startWorkflow(- getPostById.integration.providerIdentifier.split('-')[0].toLowerCase(),- getPostById.id,- orgId,- getPostById.state- );- } catch (err) {}+ if (action === 'schedule') {+ try {+ await this.startWorkflow(+ getPostById.integration.providerIdentifier.split('-')[0].toLowerCase(),+ getPostById.id,+ orgId,+ getPostById.state === 'DRAFT' ? 'DRAFT' : 'QUEUE'+ );+ } catch (err) {}+ }return newDate;}diff --git a/libraries/nestjs-libraries/src/dtos/posts/create.post.dto.ts b/libraries/nestjs-libraries/src/dtos/posts/create.post.dto.tsindex 18842f4e0..391fd56a5 100644--- a/libraries/nestjs-libraries/src/dtos/posts/create.post.dto.ts+++ b/libraries/nestjs-libraries/src/dtos/posts/create.post.dto.ts@@ -88,8 +88,8 @@ class Tags {export class CreatePostDto {@IsDefined()- @IsIn(['draft', 'schedule', 'now'])- type: 'draft' | 'schedule' | 'now';+ @IsIn(['draft', 'schedule', 'now', 'update'])+ type: 'draft' | 'schedule' | 'now' | 'update';@IsOptional()@IsString()