Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: fix providers

Nevo David68705fca691d
diff --git a/apps/frontend/src/components/launches/add.provider.component.tsx b/apps/frontend/src/components/launches/add.provider.component.tsx
index cfaad2323..20aef1115 100644
--- a/apps/frontend/src/components/launches/add.provider.component.tsx
+++ b/apps/frontend/src/components/launches/add.provider.component.tsx
@@ -104,92 +104,7 @@ export const AddProviderButton: FC<{
</div>
);
};
-export const ApiModal: FC<{
- identifier: string;
- name: string;
- update?: () => void;
- close?: () => void;
-}> = (props) => {
- const { update, name, close: closePopup } = props;
- const fetch = useFetch();
- const router = useRouter();
- const modal = useModals();
- const methods = useForm({
- mode: 'onChange',
- resolver,
- });
- const close = useCallback(() => {
- if (closePopup) {
- return closePopup();
- }
- modal.closeAll();
- }, []);
- const submit = useCallback(async (data: FieldValues) => {
- const add = await fetch(
- `/integrations/article/${props.identifier}/connect`,
- {
- method: 'POST',
- body: JSON.stringify({
- api: data.api,
- }),
- }
- );
- if (add.ok) {
- if (closePopup) {
- closePopup();
- } else {
- modal.closeAll();
- }
- router.refresh();
- if (update) update();
- return;
- }
- methods.setError('api', {
- message: t('invalid_api_key', 'Invalid API key'),
- });
- }, []);
-
- const t = useT();
- return (
- <div className="rounded-[4px] border border-customColor6 bg-sixth px-[16px] pb-[16px] relative">
- <TopTitle title={`Add API key for ${name}`} />
- <button
- onClick={close}
- className="outline-none absolute end-[20px] top-[20px] mantine-UnstyledButton-root mantine-ActionIcon-root hover:bg-tableBorder cursor-pointer mantine-Modal-close mantine-1dcetaa"
- type="button"
- >
- <svg
- viewBox="0 0 15 15"
- fill="none"
- xmlns="http://www.w3.org/2000/svg"
- width="16"
- height="16"
- >
- <path
- d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z"
- fill="currentColor"
- fillRule="evenodd"
- clipRule="evenodd"
- ></path>
- </svg>
- </button>
- <FormProvider {...methods}>
- <form
- className="gap-[8px] flex flex-col"
- onSubmit={methods.handleSubmit(submit)}
- >
- <div className="pt-[10px]">
- <Input label="API Key" name="api" />
- </div>
- <div>
- <Button type="submit">{t('add_platform', 'Add platform')}</Button>
- </div>
- </form>
- </FormProvider>
- </div>
- );
-};
export const UrlModal: FC<{
gotoUrl(url: string): void;
}> = (props) => {
diff --git a/apps/frontend/src/components/onboarding/connect.channels.tsx b/apps/frontend/src/components/onboarding/connect.channels.tsx
deleted file mode 100644
index 96ed0ea1c..000000000
--- a/apps/frontend/src/components/onboarding/connect.channels.tsx
+++ /dev/null
@@ -1,380 +0,0 @@
-'use client';
-
-import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
-import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
-import useSWR from 'swr';
-import { orderBy } from 'lodash';
-import { useUser } from '@gitroom/frontend/components/layout/user.context';
-import clsx from 'clsx';
-import Image from 'next/image';
-import { Menu } from '@gitroom/frontend/components/launches/menu/menu';
-import {
- ApiModal,
- CustomVariables,
-} from '@gitroom/frontend/components/launches/add.provider.component';
-import { useRouter } from 'next/navigation';
-import { useVariables } from '@gitroom/react/helpers/variable.context';
-import { useToaster } from '@gitroom/react/toaster/toaster';
-import { Integration } from '@prisma/client';
-import { web3List } from '@gitroom/frontend/components/launches/web3/web3.list';
-import { timer } from '@gitroom/helpers/utils/timer';
-import { deleteDialog } from '@gitroom/react/helpers/delete.dialog';
-import { useT } from '@gitroom/react/translation/get.transation.service.client';
-import { ModalWrapperComponent } from '@gitroom/frontend/components/new-launch/modal.wrapper.component';
-export const ConnectChannels: FC = () => {
- const fetch = useFetch();
- const { isGeneral } = useVariables();
- const router = useRouter();
- const [identifier, setIdentifier] = useState<any>(undefined);
- const [popup, setPopups] = useState<undefined | string[]>(undefined);
- const toaster = useToaster();
- const [showCustom, setShowCustom] = useState<any>(undefined);
- const getIntegrations = useCallback(async () => {
- return (await fetch('/integrations')).json();
- }, []);
- const [reload, setReload] = useState(false);
-
- const openWeb3 = async (id: string) => {
- const { component: Web3Providers } = web3List.find(
- (item) => item.identifier === id
- )!;
- const { url } = await (await fetch(`/integrations/social/${id}`)).json();
- setShowCustom(
- <Web3Providers
- onComplete={async (code, newState) => {
- if (
- await deleteDialog(
- 'Connection found, should we continue?',
- 'Continue'
- )
- ) {
- window.open(
- `/integrations/social/${id}?code=${code}&state=${newState}`,
- 'Social Connect',
- 'width=700,height=700'
- );
- return;
- }
- setShowCustom(undefined);
- }}
- nonce={url}
- />
- );
- return;
- };
- const refreshChannel = useCallback(
- (
- integration: Integration & {
- identifier: string;
- }
- ) =>
- async () => {
- const { url } = await (
- await fetch(
- `/integrations/social/${integration.identifier}?refresh=${integration.internalId}`,
- {
- method: 'GET',
- }
- )
- ).json();
- window.location.href = url;
- },
- []
- );
- const addMessage = useCallback(
- (
- event: MessageEvent<{
- msg: string;
- success: boolean;
- }>
- ) => {
- if (!event.data.msg) {
- return;
- }
- toaster.show(event.data.msg, event.data.success ? 'success' : 'warning');
- setShowCustom(undefined);
- },
- []
- );
- useEffect(() => {
- window.addEventListener('message', addMessage);
- return () => {
- window.removeEventListener('message', addMessage);
- };
- });
- const getSocialLink = useCallback(
- (
- identifier: string,
- isExternal: boolean,
- isWeb3: boolean,
- customFields?: Array<{
- key: string;
- label: string;
- validation: string;
- defaultValue?: string;
- type: 'text' | 'password';
- }>
- ) =>
- async () => {
- const gotoIntegration = async (externalUrl?: string) => {
- const { url, err } = await (
- await fetch(
- `/integrations/social/${identifier}${
- externalUrl ? `?externalUrl=${externalUrl}` : ``
- }`
- )
- ).json();
- if (err) {
- toaster.show('Could not connect to the platform', 'warning');
- return;
- }
- setShowCustom(undefined);
- window.open(url, 'Social Connect', 'width=700,height=700');
- };
-
- if (isWeb3) {
- openWeb3(identifier);
- return;
- }
- if (customFields) {
- setShowCustom(
- <CustomVariables
- identifier={identifier}
- gotoUrl={(url: string) =>
- window.open(url, 'Social Connect', 'width=700,height=700')
- }
- variables={customFields}
- close={() => setShowCustom(undefined)}
- />
- );
- return;
- }
- await gotoIntegration();
- },
- []
- );
- const load = useCallback(async (path: string) => {
- const list = (await (await fetch(path)).json()).integrations;
- setPopups(list.map((p: any) => p.id));
- return list;
- }, []);
-
- const { data: integrations, mutate } = useSWR('/integrations/list', load, {
- revalidateOnFocus: false,
- revalidateOnReconnect: false,
- revalidateIfStale: false,
- revalidateOnMount: true,
- refreshWhenHidden: false,
- refreshWhenOffline: false,
- fallbackData: [],
- });
-
- const user = useUser();
- const totalNonDisabledChannels = useMemo(() => {
- return (
- integrations?.filter((integration: any) => !integration.disabled)
- ?.length || 0
- );
- }, [integrations]);
-
- const sortedIntegrations = useMemo(() => {
- return orderBy(
- integrations,
- ['type', 'disabled', 'identifier'],
- ['desc', 'asc', 'asc']
- );
- }, [integrations]);
- useEffect(() => {
- if (sortedIntegrations.length === 0 || !popup) {
- return;
- }
- const betweenSteps = sortedIntegrations.find((p) => p.inBetweenSteps);
- if (betweenSteps && popup.indexOf(betweenSteps.id) === -1) {
- const url = new URL(window.location.href);
- url.searchParams.append('added', betweenSteps.identifier);
- url.searchParams.append('continue', betweenSteps.id);
- router.push(url.toString());
- setPopups([...popup, betweenSteps.id]);
- }
- }, [sortedIntegrations, popup]);
- const update = useCallback(async (shouldReload: boolean) => {
- if (shouldReload) {
- setReload(true);
- }
- await mutate();
- if (shouldReload) {
- setReload(false);
- }
- }, []);
-
- const t = useT();
-
- const continueIntegration = useCallback(
- (integration: any) => async () => {
- const url = new URL(window.location.href);
- url.searchParams.append('added', integration.identifier);
- url.searchParams.append('continue', integration.id);
- router.push(url.toString());
- },
- []
- );
- const finishUpdate = useCallback(() => {
- setIdentifier(undefined);
- update(true);
- }, []);
- const { data } = useSWR('get-all-integrations', getIntegrations);
- return (
- <>
- {!!showCustom && (
- <div className="absolute w-full h-full top-0 start-0 z-[400]">
- <div className="absolute w-full h-full bg-primary/80 start-0 top-0 z-[200] p-[50px] flex justify-center">
- <div className="w-[400px]">
- <ModalWrapperComponent
- title=""
- customClose={() => setShowCustom(undefined)}
- >
- {showCustom}
- </ModalWrapperComponent>
- </div>
- </div>
- </div>
- )}
- {!!identifier && (
- <div className="absolute w-full h-full bg-primary/80 start-0 top-0 z-[200] p-[30px] flex items-center justify-center">
- <div className="w-[400px]">
- <ApiModal
- close={() => setIdentifier(undefined)}
- update={finishUpdate}
- identifier={identifier.identifier}
- name={identifier.name}
- />
- </div>
- </div>
- )}
- <div className="flex flex-col gap-[24px]">
- <div className="flex gap-[4px] flex-col">
- <div className="text-[20px]">
- {t('connect_channels', 'Connect Channels')}
- </div>
- <div className="text-[14px] text-customColor18">
- {t(
- 'connect_your_social_media_and_publishing_websites_channels_to_schedule_posts_later',
- 'Connect your social media and publishing websites channels to\n schedule posts later'
- )}
- </div>
- </div>
- {sortedIntegrations.length !== 0 && (
- <div className="border border-customColor47 rounded-[4px] p-[16px]">
- <div className="gap-[16px] flex flex-col">
- {sortedIntegrations.length === 0 && (
- <div className="text-[12px]">
- {t('no_channels', 'No channels')}
- </div>
- )}
- {sortedIntegrations.map((integration) => (
- <div
- key={integration.id}
- className="flex gap-[8px] items-center"
- >
- <div
- className={clsx(
- 'relative w-[34px] h-[34px] rounded-full flex justify-center items-center bg-fifth',
- integration.disabled && 'opacity-50'
- )}
- >
- {integration.inBetweenSteps && (
- <div
- className="absolute start-0 top-0 w-[39px] h-[46px] cursor-pointer"
- onClick={continueIntegration(integration)}
- >
- <div className="bg-red-500 w-[15px] h-[15px] rounded-full -start-[5px] -top-[5px] absolute z-[200] text-[10px] flex justify-center items-center">
- !
- </div>
- <div className="bg-primary/60 w-[39px] h-[46px] start-0 top-0 absolute rounded-full z-[199]" />
- </div>
- )}
- <Image
- src={integration.picture}
- className="rounded-full"
- alt={integration.identifier}
- width={32}
- height={32}
- />
- <Image
- src={`/icons/platforms/${integration.identifier}.png`}
- className="rounded-full absolute z-10 -bottom-[5px] -end-[5px] border border-fifth"
- alt={integration.identifier}
- width={20}
- height={20}
- />
- </div>
- <div
- {...(integration.disabled &&
- totalNonDisabledChannels === user?.totalChannels
- ? {
- 'data-tooltip-id': 'tooltip',
- 'data-tooltip-content':
- 'This channel is disabled, please upgrade your plan to enable it.',
- }
- : {})}
- className={clsx(
- 'flex-1',
- integration.disabled && 'opacity-50'
- )}
- >
- {integration.name}
- </div>
- <Menu
- canChangeProfilePicture={integration.changeProfile}
- canChangeNickName={integration.changeNickName}
- mutate={mutate}
- onChange={update}
- id={integration.id}
- refreshChannel={refreshChannel}
- canEnable={
- user?.totalChannels! > totalNonDisabledChannels &&
- integration.disabled
- }
- canDisable={!integration.disabled}
- />
- </div>
- ))}
- </div>
- </div>
- )}
-
- <div className="flex mb-[16px]">
- <div className="flex-1 flex flex-col gap-[10px]">
- <div className="grid grid-cols-3 gap-[16px]">
- {data?.social.map((social: any) => (
- <div
- key={social.identifier}
- onClick={getSocialLink(
- social.identifier,
- social.isExternal,
- social.isWeb3,
- social.customFields
- )}
- className="h-[96px] bg-input flex flex-col justify-center items-center gap-[10px] cursor-pointer"
- >
- <div>
- <Image
- alt={social.identifier}
- src={`/icons/platforms/${social.identifier}.png`}
- className="rounded-full w-[32px] h-[32px]"
- width={32}
- height={32}
- />
- </div>
- <div className="text-textColor text-[10px] tracking-[1.2px] uppercase">
- {social.name}
- </div>
- </div>
- ))}
- </div>
- </div>
- </div>
- </div>
- </>
- );
-};
diff --git a/libraries/nestjs-libraries/src/integrations/social/dev.to.provider.ts b/libraries/nestjs-libraries/src/integrations/social/dev.to.provider.ts
index 9f59d6714..f0aee14a9 100644
--- a/libraries/nestjs-libraries/src/integrations/social/dev.to.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/dev.to.provider.ts
@@ -26,7 +26,7 @@ export class DevToProvider extends SocialAbstract implements SocialProvider {
async generateAuthUrl() {
const state = makeId(6);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};
diff --git a/libraries/nestjs-libraries/src/integrations/social/hashnode.provider.ts b/libraries/nestjs-libraries/src/integrations/social/hashnode.provider.ts
index 41c0c80fc..7eeadef06 100644
--- a/libraries/nestjs-libraries/src/integrations/social/hashnode.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/hashnode.provider.ts
@@ -28,7 +28,7 @@ export class HashnodeProvider extends SocialAbstract implements SocialProvider {
async generateAuthUrl() {
const state = makeId(6);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};
diff --git a/libraries/nestjs-libraries/src/integrations/social/lemmy.provider.ts b/libraries/nestjs-libraries/src/integrations/social/lemmy.provider.ts
index 465a0d86e..53d230d91 100644
--- a/libraries/nestjs-libraries/src/integrations/social/lemmy.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/lemmy.provider.ts
@@ -63,7 +63,7 @@ export class LemmyProvider extends SocialAbstract implements SocialProvider {
async generateAuthUrl() {
const state = makeId(6);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};
diff --git a/libraries/nestjs-libraries/src/integrations/social/listmonk.provider.ts b/libraries/nestjs-libraries/src/integrations/social/listmonk.provider.ts
index 937bb5b50..371126c22 100644
--- a/libraries/nestjs-libraries/src/integrations/social/listmonk.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/listmonk.provider.ts
@@ -65,7 +65,7 @@ export class ListmonkProvider extends SocialAbstract implements SocialProvider {
async generateAuthUrl() {
const state = makeId(6);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};
diff --git a/libraries/nestjs-libraries/src/integrations/social/medium.provider.ts b/libraries/nestjs-libraries/src/integrations/social/medium.provider.ts
index e5b8752b3..5aab52d64 100644
--- a/libraries/nestjs-libraries/src/integrations/social/medium.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/medium.provider.ts
@@ -26,7 +26,7 @@ export class MediumProvider extends SocialAbstract implements SocialProvider {
async generateAuthUrl() {
const state = makeId(6);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};
diff --git a/libraries/nestjs-libraries/src/integrations/social/nostr.provider.ts b/libraries/nestjs-libraries/src/integrations/social/nostr.provider.ts
index 04d90475f..c89f21dd7 100644
--- a/libraries/nestjs-libraries/src/integrations/social/nostr.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/nostr.provider.ts
@@ -65,7 +65,7 @@ export class NostrProvider extends SocialAbstract implements SocialProvider {
async generateAuthUrl() {
const state = makeId(17);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};
diff --git a/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts b/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
index 88e9dab99..84d199195 100644
--- a/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
@@ -32,7 +32,7 @@ export class WordpressProvider
async generateAuthUrl() {
const state = makeId(6);
return {
- url: '',
+ url: state,
codeVerifier: makeId(10),
state,
};