Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 40 additions & 32 deletions apps/backend/src/api/routes/integrations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,39 +87,47 @@ export class IntegrationsController {

@Get('/list')
async getIntegrationList(@GetOrgFromRequest() org: Organization) {
return {
integrations: await Promise.all(
(
await this._integrationService.getIntegrationsList(org.id)
).map(async (p) => {
const findIntegration = this._integrationManager.getSocialIntegration(
p.providerIdentifier
const integrations = await Promise.all(
(
await this._integrationService.getIntegrationsList(org.id)
).map(async (p) => {
const findIntegration = this._integrationManager.getSocialIntegration(
p.providerIdentifier
);
if (!findIntegration) {
console.warn(
`Skipping integration ${p.id}: provider "${p.providerIdentifier}" is not registered`
);
return {
name: p.name,
id: p.id,
internalId: p.internalId,
disabled: p.disabled,
editor: findIntegration.editor,
stripLinks: !!findIntegration?.stripLinks?.(),
picture: p.picture || '/no-picture.jpg',
identifier: p.providerIdentifier,
inBetweenSteps: p.inBetweenSteps,
refreshNeeded: p.refreshNeeded,
isCustomFields: !!findIntegration.customFields,
...(findIntegration.customFields
? { customFields: await findIntegration.customFields() }
: {}),
display: p.profile,
type: p.type,
time: JSON.parse(p.postingTimes),
changeProfilePicture: !!findIntegration?.changeProfilePicture,
changeNickName: !!findIntegration?.changeNickname,
customer: p.customer,
additionalSettings: p.additionalSettings || '[]',
};
})
),
return undefined;
}
return {
name: p.name,
id: p.id,
internalId: p.internalId,
disabled: p.disabled,
editor: findIntegration.editor,
stripLinks: !!findIntegration?.stripLinks?.(),
picture: p.picture || '/no-picture.jpg',
identifier: p.providerIdentifier,
inBetweenSteps: p.inBetweenSteps,
refreshNeeded: p.refreshNeeded,
isCustomFields: !!findIntegration.customFields,
...(findIntegration.customFields
? { customFields: await findIntegration.customFields() }
: {}),
display: p.profile,
type: p.type,
time: JSON.parse(p.postingTimes),
changeProfilePicture: !!findIntegration?.changeProfilePicture,
changeNickName: !!findIntegration?.changeNickname,
customer: p.customer,
additionalSettings: p.additionalSettings || '[]',
};
})
);

return {
integrations: integrations.filter(Boolean),
};
}

Expand Down
17 changes: 16 additions & 1 deletion apps/frontend/src/components/launches/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ const usePostActions = (onMutate?: () => void) => {
};

const data = await (await fetch(`/posts/group/${post.group}`)).json();
if (
!isDuplicate &&
data?.integration &&
!integrations.some((integration) => integration.id === data.integration)
) {
toaster.show(
t(
'post_channel_no_longer_available',
'This post belongs to a channel that is no longer available and cannot be edited.'
),
'warning'
);
return;
}

const date = !isDuplicate
? null
: (await (await fetch('/posts/find-slot')).json()).date;
Expand Down Expand Up @@ -170,7 +185,7 @@ const usePostActions = (onMutate?: () => void) => {
title: ``,
});
},
[integrations, fetch, modal, mutate]
[integrations, fetch, modal, mutate, toaster, t]
);

const copyDebugJson = useCallback(
Expand Down
20 changes: 11 additions & 9 deletions apps/frontend/src/components/launches/launches.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,18 @@ export const LaunchesComponent = () => {
const [mode] = useCookie('mode', 'dark');
const { isLoading, data: integrations, mutate } = useIntegrationList();

const totalNonDisabledChannels = useMemo(() => {
return (
integrations?.filter((integration: any) => !integration.disabled)
?.length || 0
);
const validIntegrations = useMemo(() => {
return integrations?.filter(Boolean) || [];
}, [integrations]);

const totalNonDisabledChannels = useMemo(() => {
return validIntegrations.filter((integration: any) => !integration.disabled)
.length;
}, [validIntegrations]);
const changeItemGroup = useCallback(
async (id: string, group: string) => {
mutate(
integrations.map((integration: any) => {
validIntegrations.map((integration: any) => {
if (integration.id === id) {
return {
...integration,
Expand All @@ -393,15 +395,15 @@ export const LaunchesComponent = () => {
});
mutate();
},
[integrations]
[validIntegrations]
);
const sortedIntegrations = useMemo(() => {
return orderBy(
integrations,
validIntegrations,
['type', 'disabled', 'identifier'],
['desc', 'asc', 'asc']
);
}, [integrations]);
}, [validIntegrations]);
const menuIntegrations = useMemo(() => {
return orderBy(
Object.values(
Expand Down
31 changes: 24 additions & 7 deletions apps/frontend/src/components/new-launch/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ interface StoreState {
setAllIntegrations: (integrations: Integrations[]) => void;
setCurrent: (current: string) => void;
addOrRemoveSelectedIntegration: (
integration: Integrations,
integration: Integrations | undefined,
settings: any
) => void;
reset: () => void;
Expand Down Expand Up @@ -164,9 +164,13 @@ export const useLaunchStore = create<StoreState>()((set) => ({
current: current,
})),
addOrRemoveSelectedIntegration: (
integration: Integrations,
integration: Integrations | undefined,
settings: any
) => {
if (!integration) {
return;
}

set((state) => {
const existing = state.selectedIntegrations.find(
(i) => i.integration.id === integration.id
Expand Down Expand Up @@ -224,13 +228,19 @@ export const useLaunchStore = create<StoreState>()((set) => ({
);

if (integrationIndex === -1) {
const selectedIntegration = state.selectedIntegrations.find(
(i) => i.integration?.id === integrationId
);

if (!selectedIntegration) {
return {};
}

return {
internal: [
...state.internal,
{
integration: state.selectedIntegrations.find(
(i) => i.integration.id === integrationId
)!.integration,
integration: selectedIntegration.integration,
integrationValue: value,
},
],
Expand Down Expand Up @@ -301,7 +311,7 @@ export const useLaunchStore = create<StoreState>()((set) => ({
addRemoveInternal: (integrationId: string) =>
set((state) => {
const integration = state.selectedIntegrations.find(
(i) => i.integration.id === integrationId
(i) => i.integration?.id === integrationId
);
const findIntegrationIndex = state.internal.findIndex(
(i) => i.integration.id === integrationId
Expand All @@ -315,6 +325,10 @@ export const useLaunchStore = create<StoreState>()((set) => ({
};
}

if (!integration) {
return {};
}

return {
internal: [
...state.internal,
Expand Down Expand Up @@ -369,7 +383,10 @@ export const useLaunchStore = create<StoreState>()((set) => ({
if (item.integration.id === integrationId) {
const targetIndex = direction === 'up' ? index - 1 : index + 1;

if (targetIndex < 0 || targetIndex >= item.integrationValue.length) {
if (
targetIndex < 0 ||
targetIndex >= item.integrationValue.length
) {
return item;
}

Expand Down