-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Notifications): Refactor notification settings to be per team (#…
- Loading branch information
1 parent
8ac649d
commit 49dc95a
Showing
52 changed files
with
721 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
packages/client/mutations/SetNotificationSettingMutation.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
packages/client/mutations/SetTeamNotificationSettingMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.