()
| 52 | } |
| 53 | |
| 54 | export const SlackConnectView = () => { |
| 55 | const { t } = useTranslate(); |
| 56 | const location = useLocation(); |
| 57 | const user = useUser(); |
| 58 | const history = useHistory(); |
| 59 | |
| 60 | const queryParameters = new URLSearchParams(location.search); |
| 61 | const encryptedData = queryParameters.get('data'); |
| 62 | |
| 63 | const slackMutation = useApiMutation({ |
| 64 | url: '/v2/slack/user-login', |
| 65 | method: 'post', |
| 66 | fetchOptions: { |
| 67 | disableErrorNotification: true, |
| 68 | }, |
| 69 | }); |
| 70 | |
| 71 | const connectionInfo = useApiQuery({ |
| 72 | url: '/v2/slack/user-login-info', |
| 73 | method: 'get', |
| 74 | query: { |
| 75 | data: encryptedData!, |
| 76 | }, |
| 77 | fetchOptions: { |
| 78 | disableErrorNotification: true, |
| 79 | }, |
| 80 | }); |
| 81 | |
| 82 | if (!encryptedData) { |
| 83 | return <div>Invalid slack login parameters</div>; |
| 84 | } |
| 85 | const connectSlack = () => { |
| 86 | slackMutation.mutate( |
| 87 | { query: { data: encryptedData } }, |
| 88 | { |
| 89 | onSuccess: () => { |
| 90 | history.replace(LINKS.SLACK_CONNECTED.build()); |
| 91 | }, |
| 92 | } |
| 93 | ); |
| 94 | }; |
| 95 | |
| 96 | const error = slackMutation.error || connectionInfo.error; |
| 97 | |
| 98 | return ( |
| 99 | <DashboardPage> |
| 100 | <CompactView |
| 101 | alerts={ |
| 102 | error?.code && ( |
| 103 | <Alert severity="error" sx={{ mb: 1 }}> |
| 104 | <TranslatedError code={error.code} /> |
| 105 | </Alert> |
| 106 | ) |
| 107 | } |
| 108 | maxWidth={800} |
| 109 | windowTitle={t('slack_connect_title')} |
| 110 | primaryContent={ |
| 111 | <> |
nothing calls this directly
no test coverage detected