Skip to content

Commit

Permalink
Merge pull request #316 from meemproject/feature/symphony-multi-io
Browse files Browse the repository at this point in the history
Hooking up slack WIP
  • Loading branch information
kengoldfarb committed Mar 20, 2023
2 parents 7840383 + dd50223 commit a2d4143
Show file tree
Hide file tree
Showing 12 changed files with 41,632 additions and 30,141 deletions.
69,816 changes: 39,871 additions & 29,945 deletions generated/graphql.schema.json

Large diffs are not rendered by default.

1,623 changes: 1,611 additions & 12 deletions generated/graphql.tsx

Large diffs are not rendered by default.

Expand Up @@ -4,10 +4,8 @@ import { Space, Modal, Text, Grid, Image } from '@mantine/core'
import { MoreVert } from 'iconoir-react'
import React, { useState } from 'react'
import { useMeemTheme } from '../../../Styles/MeemTheme'
import {
SymphonyConnection,
SymphonyConnectionPlatform
} from '../Model/symphony'
import { SymphonyConnection } from '../Model/symphony'
import { API } from '../symphonyTypes.generated'
// import { API } from '../symphonyTypes.generated'
import { SymphonyDisconnectModal } from './SymphonyDisconnectModal'
import { SymphonyDiscordConnectionModal } from './SymphonyDiscordConnectionModal'
Expand Down Expand Up @@ -75,15 +73,15 @@ export const SymphonyConnectionsModal: React.FC<IProps> = ({
// const handleReauthenticate = useCallback(async () => {
// if (selectedConnection) {
// switch (selectedConnection.platform) {
// case SymphonyConnectionPlatform.Discord:
// case API.RuleIo.Discord:
// setIsConnectDiscordModalOpen(true)
// break

// case SymphonyConnectionPlatform.Twitter:
// case API.RuleIo.Twitter:
// handleAuthTwitter()
// break

// case SymphonyConnectionPlatform.Slack:
// case API.RuleIo.Slack:
// handleAuthSlack()
// break

Expand Down Expand Up @@ -166,15 +164,15 @@ export const SymphonyConnectionsModal: React.FC<IProps> = ({

const ConnectionsList = () => {
const twitterConnections = connections?.filter(
c => c.platform === SymphonyConnectionPlatform.Twitter
c => c.platform === API.RuleIo.Twitter
)

const discordConnections = connections?.filter(
c => c.platform === SymphonyConnectionPlatform.Discord
c => c.platform === API.RuleIo.Discord
)

const slackConnections = connections?.filter(
c => c.platform === SymphonyConnectionPlatform.Slack
c => c.platform === API.RuleIo.Slack
)

return (
Expand Down
Expand Up @@ -10,11 +10,7 @@ import {
} from '../../../../utils/notifications'
import { useAgreement } from '../../../AgreementHome/AgreementProvider'
import { useMeemTheme } from '../../../Styles/MeemTheme'
import {
SymphonyConnection,
SymphonyConnectionPlatform,
SymphonyConnectionType
} from '../Model/symphony'
import { SymphonyConnection, SymphonyConnectionType } from '../Model/symphony'
import { API } from '../symphonyTypes.generated'

interface IProps {
Expand All @@ -40,7 +36,7 @@ export const SymphonyDisconnectModal: React.FC<IProps> = ({
try {
// TODO: Slack
switch (connection.platform) {
case SymphonyConnectionPlatform.Discord:
case API.RuleIo.Discord:
await makeRequest<API.v1.DisconnectDiscord.IDefinition>(
`${
process.env.NEXT_PUBLIC_SYMPHONY_API_URL
Expand All @@ -61,7 +57,7 @@ export const SymphonyDisconnectModal: React.FC<IProps> = ({

break

case SymphonyConnectionPlatform.Twitter:
case API.RuleIo.Twitter:
await makeRequest<API.v1.DisconnectTwitter.IDefinition>(
`${
process.env.NEXT_PUBLIC_SYMPHONY_API_URL
Expand Down Expand Up @@ -117,11 +113,10 @@ export const SymphonyDisconnectModal: React.FC<IProps> = ({
style={{ textAlign: 'center' }}
>
{`Are you sure you want to disconnect ${
connection.platform ===
SymphonyConnectionPlatform.Discord
connection.platform === API.RuleIo.Discord
? 'Discord'
: connection.platform ===
SymphonyConnectionPlatform.Twitter
API.RuleIo.Twitter
? 'Twitter'
: 'Slack'
} from
Expand Down
Expand Up @@ -22,7 +22,6 @@ import { useAgreement } from '../../../AgreementHome/AgreementProvider'
import { useMeemTheme } from '../../../Styles/MeemTheme'
import {
SymphonyConnection,
SymphonyConnectionPlatform,
SymphonyConnectionType,
SymphonyRule
} from '../Model/symphony'
Expand Down Expand Up @@ -88,7 +87,7 @@ export const SymphonyInputOutputModal: React.FC<IProps> = ({

// Save the rule
const handleRuleSave = async (values: IOnSave) => {
if (!agreement?.id || !jwt) {
if (!agreement?.id || !jwt || !selectedInput || !selectedOutput) {
return
}

Expand All @@ -105,10 +104,10 @@ export const SymphonyInputOutputModal: React.FC<IProps> = ({
agreementId: agreement.id,
rule: {
...values,
input: API.RuleIo.Discord,
input: selectedInput.platform,
inputRef:
existingRule?.input.id ?? selectedInput?.id ?? '',
output: API.RuleIo.Twitter,
output: selectedOutput.platform,
outputRef:
existingRule?.output.id ?? selectedOutput?.id ?? '',
isEnabled: true,
Expand Down Expand Up @@ -158,17 +157,15 @@ export const SymphonyInputOutputModal: React.FC<IProps> = ({
const openRuleBuilder = useCallback(() => {
if (selectedInput && selectedOutput) {
if (
selectedInput.platform === SymphonyConnectionPlatform.Discord &&
selectedOutput.platform ===
SymphonyConnectionPlatform.Twitter &&
selectedInput.platform === API.RuleIo.Discord &&
selectedOutput.platform === API.RuleIo.Twitter &&
!isDiscordTwitterRuleBuilderOpened
) {
// Discord to Twitter flow
setIsDiscordTwitterRuleBuilderOpened(true)
} else if (
selectedInput.platform === SymphonyConnectionPlatform.Slack &&
selectedOutput.platform ===
SymphonyConnectionPlatform.Twitter &&
selectedInput.platform === API.RuleIo.Slack &&
selectedOutput.platform === API.RuleIo.Twitter &&
!isSlackTwitterRuleBuilderOpened
) {
// Discord to Twitter flow
Expand Down Expand Up @@ -245,7 +242,7 @@ export const SymphonyInputOutputModal: React.FC<IProps> = ({
const shouldShowNext =
selectedInput &&
selectedOutput &&
(selectedOutput.platform !== SymphonyConnectionPlatform.WebHook ||
(selectedOutput.platform !== API.RuleIo.Webhook ||
(webhookUrl && webhookUrl.includes('https://')))

const modalContents = (
Expand Down Expand Up @@ -318,8 +315,7 @@ export const SymphonyInputOutputModal: React.FC<IProps> = ({
}}
/>
{selectedOutput &&
selectedOutput.platform ===
SymphonyConnectionPlatform.WebHook && (
selectedOutput.platform === API.RuleIo.Webhook && (
<>
<Space h={24} />
<Text className={meemTheme.tSmallBold}>
Expand Down Expand Up @@ -463,16 +459,12 @@ export const SymphonyInputOutputModal: React.FC<IProps> = ({
onSave={function (values: IOnSave): void {
handleRuleSave(values)
}}
slackId={
existingRule?.input.id ?? selectedInput?.id ?? ''
}
twitterId={
existingRule?.output.id ?? selectedOutput?.id ?? ''
}
input={existingRule?.input ?? selectedInput}
output={existingRule?.output ?? selectedOutput}
rule={existingRule}
isOpened={isDiscordTwitterRuleBuilderOpened}
isOpened={isSlackTwitterRuleBuilderOpened}
onModalClosed={function (): void {
setIsDiscordTwitterRuleBuilderOpened(false)
setIsSlackTwitterRuleBuilderOpened(false)
}}
/>
</>
Expand Down
16 changes: 9 additions & 7 deletions src/components/Extensions/Symphony/Model/symphony.tsx
Expand Up @@ -6,18 +6,18 @@ export enum SymphonyConnectionType {
OutputOnly
}

export enum SymphonyConnectionPlatform {
Twitter,
Discord,
Slack,
WebHook
}
// export enum SymphonyConnectionPlatform {
// Twitter,
// Discord,
// Slack,
// WebHook
// }

export interface SymphonyConnection {
id: string
name: string
type: SymphonyConnectionType
platform: SymphonyConnectionPlatform
platform: API.RuleIo
icon?: string

// Twitter
Expand All @@ -39,4 +39,6 @@ export interface SymphonyRule {
output: SymphonyConnection
agreementId: string
definition: API.IRule
description?: string | null
abridgedDescription?: string | null
}
Expand Up @@ -121,7 +121,11 @@ export const SymphonyDiscordTwitterRulesBuilder: React.FC<IProps> = ({
agreementId: agreement?.id,
twitterId: rule?.output?.id ?? output?.id ?? ''
},
skip: !symphonyClient || !agreement?.id || !isOpened,
skip:
!symphonyClient ||
!agreement?.id ||
!isOpened ||
!rule?.output?.id,
client: symphonyClient
})

Expand All @@ -131,7 +135,11 @@ export const SymphonyDiscordTwitterRulesBuilder: React.FC<IProps> = ({
agreementId: agreement?.id,
discordId: rule?.input?.id ?? input?.id ?? ''
},
skip: !symphonyClient || !agreement?.id || !isOpened,
skip:
!symphonyClient ||
!agreement?.id ||
!isOpened ||
!rule?.input?.id,
client: symphonyClient
})

Expand Down
@@ -1,10 +1,8 @@
import { Text, Space, Image, Button } from '@mantine/core'
import React from 'react'
import { useMeemTheme } from '../../../Styles/MeemTheme'
import {
SymphonyConnection,
SymphonyConnectionPlatform
} from '../Model/symphony'
import { SymphonyConnection } from '../Model/symphony'
import { API } from '../symphonyTypes.generated'

interface IProps {
input?: SymphonyConnection
Expand All @@ -24,17 +22,16 @@ export const SymphonyRuleBuilderConnections: React.FC<IProps> = ({
const { classes: meemTheme } = useMeemTheme()

const inputIcon =
input?.platform === SymphonyConnectionPlatform.Discord
input?.platform === API.RuleIo.Discord
? '/connect-discord.png'
: '/connect-slack.png'

const outputIcon =
output?.platform === SymphonyConnectionPlatform.Twitter
output?.platform === API.RuleIo.Twitter
? '/connect-twitter.png'
: '/connect-webhook.png'

const isOutputWebhook =
output?.platform === SymphonyConnectionPlatform.WebHook
const isOutputWebhook = output?.platform === API.RuleIo.Webhook

return (
<>
Expand Down

0 comments on commit a2d4143

Please sign in to comment.