Skip to content

Commit

Permalink
chore(Notifications): Refactor notification settings to be per team (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch authored Mar 3, 2025
1 parent 8ac649d commit 49dc95a
Show file tree
Hide file tree
Showing 52 changed files with 721 additions and 562 deletions.
10 changes: 6 additions & 4 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
"GifResponse": "./types/GifResponse#GifResponseSource",
"GitHubIntegration": "../../postgres/queries/getGitHubAuthByUserIdTeamId#GitHubAuth",
"GitLabIntegration": "./types/GitLabIntegration#GitLabIntegrationSource",
"IntegrationProviderOAuth1": "../../postgres/queries/getIntegrationProvidersByIds#TIntegrationProvider",
"IntegrationProviderOAuth2": "../../postgres/queries/getIntegrationProvidersByIds#TIntegrationProvider",
"IntegrationProviderWebhook": "../../postgres/queries/getIntegrationProvidersByIds#TIntegrationProvider",
"IntegrationProvider": "./types/IntegrationProvider#IntegrationProviderSource",
"IntegrationProviderOAuth1": "./types/IntegrationProviderOAuth1#IntegrationProviderOAuth1Source",
"IntegrationProviderOAuth2": "./types/IntegrationProviderOAuth2#IntegrationProviderOAuth2Source",
"IntegrationProviderWebhook": "./types/IntegrationProviderWebhook#IntegrationProviderWebhookSource",
"InviteToTeamPayload": "./types/InviteToTeamPayload#InviteToTeamPayloadSource",
"JiraIssue": "./types/JiraIssue#JiraIssueSource",
"JiraRemoteAvatarUrls": "./types/JiraRemoteAvatarUrls#JiraRemoteAvatarUrlsSource",
Expand Down Expand Up @@ -163,9 +164,9 @@
"SetDefaultSlackChannelSuccess": "./types/SetDefaultSlackChannelSuccess#SetDefaultSlackChannelSuccessSource",
"SetMeetingSettingsPayload": "../types/SetMeetingSettingsPayload#SetMeetingSettingsPayloadSource",
"SetNotificationStatusPayload": "./types/SetNotificationStatusPayload#SetNotificationStatusPayloadSource",
"SetNotificationSettingSuccess": "./types/SetNotificationSettingSuccess#SetNotificationSettingSuccessSource",
"SetOrgUserRoleSuccess": "./types/SetOrgUserRoleSuccess#SetOrgUserRoleSuccessSource",
"SetSlackNotificationPayload": "./types/SetSlackNotificationPayload#SetSlackNotificationPayloadSource",
"SetTeamNotificationSettingSuccess": "./types/SetTeamNotificationSettingSuccess#SetTeamNotificationSettingSuccessSource",
"ShareTopicSuccess": "./types/ShareTopicSuccess#ShareTopicSuccessSource",
"SlackIntegration": "../../postgres/types/index#SlackAuth as SlackAuthDB",
"SlackNotification": "../../postgres/types/index#SlackNotification as SlackNotificationDB",
Expand All @@ -186,6 +187,7 @@
"TeamMemberIntegrationAuthOAuth2": "../../postgres/queries/getTeamMemberIntegrationAuth#TeamMemberIntegrationAuth",
"TeamMemberIntegrationAuthWebhook": "../../postgres/queries/getTeamMemberIntegrationAuth#TeamMemberIntegrationAuth",
"TeamMemberIntegrations": "./types/TeamMemberIntegrations#TeamMemberIntegrationsSource",
"TeamNotificationSettings": "./types/TeamNotificationSettings#TeamNotificationSettingsSource",
"TeamPromptMeeting": "../../postgres/types/Meeting#TeamPromptMeeting",
"TeamPromptMeetingMember": "../../postgres/types/Meeting.d#TeamPromptMeetingMember as TeamPromptMeetingMemberDB",
"TeamPromptMeetingSettings": "../../postgres/types/index#MeetingSettings as TeamMeetingSettingsDB",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"husky": "^7.0.4",
"jscodeshift": "^0.14.0",
"kysely": "^0.27.5",
"kysely-codegen": "^0.15.0",
"kysely-codegen": "^0.17.0",
"kysely-ctl": "^0.11.0",
"lerna": "^6.4.1",
"mini-css-extract-plugin": "^2.7.2",
Expand Down
19 changes: 11 additions & 8 deletions packages/client/components/StageTimerModalEndTimeSlackToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ const StyledNotificationErrorMessage = styled(NotificationErrorMessage)({
})

const isNotificationActive = (integration: {
auth: null | undefined | {isActive: boolean; events: readonly SlackNotificationEventEnum[]}
isActive: boolean
teamNotificationSettings: {events: readonly SlackNotificationEventEnum[]} | null | undefined
}) => {
const {auth} = integration
if (!auth?.isActive) return false
const {events} = auth
const {isActive, teamNotificationSettings} = integration
if (!isActive || !teamNotificationSettings) return false
const {events} = teamNotificationSettings
if (!events) return false
return (
events.includes('MEETING_STAGE_TIME_LIMIT_START') ||
Expand All @@ -81,14 +82,16 @@ const StageTimerModalEndTimeSlackToggle = (props: Props) => {
teamId
integrations {
mattermost {
auth {
isActive
isActive
teamNotificationSettings {
id
events
}
}
msTeams {
auth {
isActive
isActive
teamNotificationSettings {
id
events
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ const MSTeamsPanel = (props: Props) => {
integrations {
msTeams {
auth {
...NotificationSettings_auth
provider {
id
webhookUrl
}
}
teamNotificationSettings {
...NotificationSettings_settings
}
}
}
}
Expand All @@ -89,7 +91,7 @@ const MSTeamsPanel = (props: Props) => {
const {teamMember} = viewer
const {integrations} = teamMember!
const {msTeams} = integrations
const {auth} = msTeams
const {teamNotificationSettings, auth} = msTeams
const activeProvider = auth?.provider
const atmosphere = useAtmosphere()

Expand Down Expand Up @@ -209,7 +211,7 @@ const MSTeamsPanel = (props: Props) => {
{fieldError && <StyledError>{fieldError}</StyledError>}
{!fieldError && mutationError && <StyledError>{mutationError.message}</StyledError>}
</form>
{auth && <NotificationSettings auth={auth} />}
{teamNotificationSettings && <NotificationSettings settings={teamNotificationSettings} />}
</MSTeamsPanelStyles>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ graphql`
fragment MSTeamsProviderRowTeamMemberIntegrations on TeamMemberIntegrations {
msTeams {
auth {
...NotificationSettings_auth
provider {
id
}
}
teamNotificationSettings {
...NotificationSettings_settings
}
}
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ const MattermostPanel = (props: Props) => {
integrations {
mattermost {
auth {
...NotificationSettings_auth
provider {
id
webhookUrl
}
}
teamNotificationSettings {
...NotificationSettings_settings
}
}
}
}
Expand All @@ -103,7 +105,7 @@ const MattermostPanel = (props: Props) => {
const {teamMember} = viewer
const {integrations} = teamMember!
const {mattermost} = integrations
const {auth} = mattermost
const {teamNotificationSettings, auth} = mattermost
const activeProvider = auth?.provider
const atmosphere = useAtmosphere()

Expand Down Expand Up @@ -224,7 +226,7 @@ const MattermostPanel = (props: Props) => {
{fieldError && <StyledError>{fieldError}</StyledError>}
{!fieldError && mutationError && <StyledError>{mutationError.message}</StyledError>}
</form>
{auth && <NotificationSettings auth={auth} />}
{teamNotificationSettings && <NotificationSettings settings={teamNotificationSettings} />}
</MattermostPanelStyles>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ graphql`
fragment MattermostProviderRowTeamMemberIntegrations on TeamMemberIntegrations {
mattermost {
auth {
...NotificationSettings_auth
provider {
id
}
}
teamNotificationSettings {
...NotificationSettings_settings
}
}
}
`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import graphql from 'babel-plugin-relay/macro'
import {useFragment} from 'react-relay'
import {
NotificationSettings_auth$key,
NotificationSettings_settings$key,
SlackNotificationEventEnum
} from '../../../../__generated__/NotificationSettings_auth.graphql'
} from '../../../../__generated__/NotificationSettings_settings.graphql'
import StyledError from '../../../../components/StyledError'
import Toggle from '../../../../components/Toggle/Toggle'
import useAtmosphere from '../../../../hooks/useAtmosphere'
import useMutationProps from '../../../../hooks/useMutationProps'
import SetNotificationSettingMutation from '../../../../mutations/SetNotificationSettingMutation'
import SetTeamNotificationSettingMutation from '../../../../mutations/SetTeamNotificationSettingMutation'
import {MeetingLabels} from '../../../../types/constEnums'

const EVENTS = [
Expand All @@ -31,21 +31,21 @@ const labelLookup = {
} as Record<SlackNotificationEventEnum, string>

interface Props {
auth: NotificationSettings_auth$key
settings: NotificationSettings_settings$key
}

const NotificationSettings = (props: Props) => {
const {auth: authRef} = props
const auth = useFragment(
const {settings: settingsRef} = props
const settings = useFragment(
graphql`
fragment NotificationSettings_auth on TeamMemberIntegrationAuthWebhook {
fragment NotificationSettings_settings on TeamNotificationSettings {
id
events
}
`,
authRef
settingsRef
)
const {events} = auth
const {events} = settings

const atmosphere = useAtmosphere()
const {submitting, onError, onCompleted, submitMutation, error} = useMutationProps()
Expand All @@ -54,10 +54,10 @@ const NotificationSettings = (props: Props) => {
return
}
submitMutation()
SetNotificationSettingMutation(
SetTeamNotificationSettingMutation(
atmosphere,
{
authId: auth.id,
id: settings.id,
event,
isEnabled
},
Expand Down
59 changes: 0 additions & 59 deletions packages/client/mutations/SetNotificationSettingMutation.ts

This file was deleted.

59 changes: 59 additions & 0 deletions packages/client/mutations/SetTeamNotificationSettingMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import graphql from 'babel-plugin-relay/macro'
import {commitMutation} from 'react-relay'
import {
SlackNotificationEventEnum,
SetTeamNotificationSettingMutation as TSetTeamNotificationSettingMutation
} from '../__generated__/SetTeamNotificationSettingMutation.graphql'
import {StandardMutation} from '../types/relayMutations'

graphql`
fragment SetTeamNotificationSettingMutation_settings on SetTeamNotificationSettingSuccess {
teamNotificationSettings {
id
events
}
}
`

const mutation = graphql`
mutation SetTeamNotificationSettingMutation(
$id: ID!
$event: SlackNotificationEventEnum!
$isEnabled: Boolean!
) {
setTeamNotificationSetting(id: $id, event: $event, isEnabled: $isEnabled) {
... on ErrorPayload {
error {
message
}
}
...SetTeamNotificationSettingMutation_settings @relay(mask: false)
}
}
`

const SetTeamNotificationMutation: StandardMutation<TSetTeamNotificationSettingMutation> = (
atmosphere,
variables,
{onError, onCompleted}
) => {
return commitMutation<TSetTeamNotificationSettingMutation>(atmosphere, {
mutation,
variables,
optimisticUpdater: (store) => {
const {id, event, isEnabled} = variables
const settings = store.get(id)
if (!settings) return
const enabledEvents = settings.getValue('events') as SlackNotificationEventEnum[]
if (!enabledEvents) return
const newEvents = isEnabled
? [...enabledEvents, event]
: enabledEvents.filter((enabledEvent) => enabledEvent !== event)
settings.setValue(newEvents, 'events')
},
onCompleted,
onError
})
}

export default SetTeamNotificationMutation
6 changes: 6 additions & 0 deletions packages/client/shared/gqlIds/TeamNotificationSettingsId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const TeamNotificationSettingsId = {
join: (id: number) => `teamNotificationSettings:${id}`,
split: (id: string) => parseInt(id.split(':')[1]!)
}

export default TeamNotificationSettingsId
5 changes: 2 additions & 3 deletions packages/client/subscriptions/TeamSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ const subscription = graphql`
SetMeetingSettingsPayload {
...SetMeetingSettingsMutation_team @relay(mask: false)
}
SetNotificationSettingSuccess {
...SetNotificationSettingMutation_auth @relay(mask: false)
SetTeamNotificationSettingSuccess {
...SetTeamNotificationSettingMutation_settings @relay(mask: false)
}
StartCheckInSuccess {
...StartCheckInMutation_team @relay(mask: false)
Expand All @@ -170,7 +170,6 @@ const subscription = graphql`
UpdateAgendaItemPayload {
...UpdateAgendaItemMutation_team @relay(mask: false)
}
UpdateCreditCardPayload {
...UpdateCreditCardMutation_team @relay(mask: false)
}
Expand Down
Loading

0 comments on commit 49dc95a

Please sign in to comment.