diff --git a/apps/frontend/src/components/new-launch/manage.modal.tsx b/apps/frontend/src/components/new-launch/manage.modal.tsx index be53586b..e5ab8e17 100644 --- a/apps/frontend/src/components/new-launch/manage.modal.tsx +++ b/apps/frontend/src/components/new-launch/manage.modal.tsx @@ -412,6 +412,8 @@ export const ManageModal: FC = (props) => { ? 'Create output' : !existingData?.integration ? t('add_to_calendar', 'Add to calendar') + : existingData?.posts?.[0]?.state === 'DRAFT' + ? t('schedule', 'Schedule') : t('update', 'Update')} {!dummy && ( diff --git a/apps/frontend/src/components/new-launch/providers/facebook/facebook.provider.tsx b/apps/frontend/src/components/new-launch/providers/facebook/facebook.provider.tsx index 9d0e66de..68fdbf20 100644 --- a/apps/frontend/src/components/new-launch/providers/facebook/facebook.provider.tsx +++ b/apps/frontend/src/components/new-launch/providers/facebook/facebook.provider.tsx @@ -4,12 +4,29 @@ import { PostComment, withProvider, } from '@gitroom/frontend/components/new-launch/providers/high.order.provider'; +import { FacebookDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/facebook.dto'; +import { Input } from '@gitroom/react/form/input'; +import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values'; + +export const FacebookSettings = () => { + const { register } = useSettings(); + + return ( + + ); +}; + export default withProvider({ postComment: PostComment.COMMENT, minimumCharacters: [], - SettingsComponent: null, + SettingsComponent: FacebookSettings, CustomPreviewComponent: undefined, - dto: undefined, + dto: FacebookDto, checkValidity: undefined, maximumCharacters: 63206, }); diff --git a/libraries/nestjs-libraries/src/dtos/posts/providers-settings/facebook.dto.ts b/libraries/nestjs-libraries/src/dtos/posts/providers-settings/facebook.dto.ts new file mode 100644 index 00000000..5743e03a --- /dev/null +++ b/libraries/nestjs-libraries/src/dtos/posts/providers-settings/facebook.dto.ts @@ -0,0 +1,8 @@ +import { IsOptional, ValidateIf, IsUrl } from 'class-validator'; + +export class FacebookDto { + @IsOptional() + @ValidateIf(p => p.url) + @IsUrl() + url?: string; +} diff --git a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts index 0771578e..a5d68f6f 100644 --- a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts @@ -8,6 +8,7 @@ import { import { makeId } from '@gitroom/nestjs-libraries/services/make.is'; import dayjs from 'dayjs'; import { SocialAbstract } from '@gitroom/nestjs-libraries/integrations/social.abstract'; +import { FacebookDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/facebook.dto'; export class FacebookProvider extends SocialAbstract implements SocialProvider { identifier = 'facebook'; @@ -22,10 +23,12 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider { 'read_insights', ]; - override handleErrors(body: string): { - type: 'refresh-token' | 'bad-body'; - value: string; - } | undefined { + override handleErrors(body: string): + | { + type: 'refresh-token' | 'bad-body'; + value: string; + } + | undefined { // Access token validation errors - require re-authentication if (body.indexOf('Error validating access token') > -1) { return { @@ -274,7 +277,7 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider { async post( id: string, accessToken: string, - postDetails: PostDetails[] + postDetails: PostDetails[] ): Promise { const [firstPost, ...comments] = postDetails; @@ -345,6 +348,9 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider { }, body: JSON.stringify({ ...(uploadPhotos?.length ? { attached_media: uploadPhotos } : {}), + ...(firstPost?.settings?.url + ? { link: firstPost.settings.url } + : {}), message: firstPost.message, published: true, }),