diff --git a/src/components/PageErrorHandlingWrapper/PageErrorHandlingWrapper.helpers.tsx b/src/components/PageErrorHandlingWrapper/PageErrorHandlingWrapper.helpers.tsx index a9a4432ade..b6f808a535 100644 --- a/src/components/PageErrorHandlingWrapper/PageErrorHandlingWrapper.helpers.tsx +++ b/src/components/PageErrorHandlingWrapper/PageErrorHandlingWrapper.helpers.tsx @@ -8,7 +8,7 @@ export function getWrongTeamResponseInfo(response): Partial { if (response) { if (response.status === 404) { return { isNotFoundError: true }; - } else if (response.status === 403 && response.data.error_code === 'wrong_team') { + } else if (response.status === 403 && response.data?.error_code === 'wrong_team') { let res = response.data; if (res.owner_team) { return { isWrongTeamError: true, switchToTeam: { name: res.owner_team.name, id: res.owner_team.id } }; diff --git a/src/containers/DefaultPageLayout/DefaultPageLayout.helpers.tsx b/src/containers/DefaultPageLayout/DefaultPageLayout.helpers.tsx index b13b7bc4bf..4e54700e06 100644 --- a/src/containers/DefaultPageLayout/DefaultPageLayout.helpers.tsx +++ b/src/containers/DefaultPageLayout/DefaultPageLayout.helpers.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { PluginLink } from 'components/PluginLink/PluginLink'; +import { RenderConditionally } from 'components/RenderConditionally/RenderConditionally'; import { Organization } from 'models/organization/organization.types'; import { SlackError } from './DefaultPageLayout.types'; @@ -10,12 +11,15 @@ export function getSlackMessage(slackError: SlackError, organization: Organizati return ( <> Couldn't connect Slack. - {Boolean(organization?.slack_team_identity) && ( - <> - {' '} - Select {organization.slack_team_identity.cached_name} workspace when connecting please - - )} + ( + <> + {' '} + Select {organization.slack_team_identity.cached_name} workspace when connecting please + + )} + /> ); } diff --git a/src/containers/OutgoingWebhookForm/OutgoingWebhookForm.tsx b/src/containers/OutgoingWebhookForm/OutgoingWebhookForm.tsx index 231cf7ef00..8dc52c59cc 100644 --- a/src/containers/OutgoingWebhookForm/OutgoingWebhookForm.tsx +++ b/src/containers/OutgoingWebhookForm/OutgoingWebhookForm.tsx @@ -74,7 +74,7 @@ function prepareDataForEdit( function prepareForSave(rawData: Partial, selectedPreset: OutgoingWebhookPreset) { const data = { ...rawData }; - selectedPreset.controlled_fields.forEach((field) => { + selectedPreset?.controlled_fields.forEach((field) => { delete data[field]; }); diff --git a/src/containers/OutgoingWebhookForm/OutgoingWebhookFormFields.tsx b/src/containers/OutgoingWebhookForm/OutgoingWebhookFormFields.tsx index 4e3d7a4c03..c493acb6c6 100644 --- a/src/containers/OutgoingWebhookForm/OutgoingWebhookFormFields.tsx +++ b/src/containers/OutgoingWebhookForm/OutgoingWebhookFormFields.tsx @@ -354,7 +354,7 @@ export const OutgoingWebhookFormFields = ({ return ( <> {React.Children.toArray(controls.props.children).filter( - (child) => !preset || !preset.controlled_fields.includes((child as React.ReactElement).props.name) + (child) => !preset?.controlled_fields.includes((child as React.ReactElement).props.name) )} ); diff --git a/src/containers/OutgoingWebhookForm/WebhookPresetIcons.config.tsx b/src/containers/OutgoingWebhookForm/WebhookPresetIcons.config.tsx index f0554656e1..7ce82803f8 100644 --- a/src/containers/OutgoingWebhookForm/WebhookPresetIcons.config.tsx +++ b/src/containers/OutgoingWebhookForm/WebhookPresetIcons.config.tsx @@ -10,7 +10,7 @@ export const additionalWebhookPresetIcons: { [id: string]: () => React.ReactElem }; export const getWebhookPresetIcons = (features: Record) => { - if (features[AppFeature.MsTeams]) { + if (features?.[AppFeature.MsTeams]) { return { ...commonWebhookPresetIconsConfig, ...additionalWebhookPresetIcons }; } diff --git a/src/containers/RotationForm/RotationForm.tsx b/src/containers/RotationForm/RotationForm.tsx index ef16aed45a..23799c0520 100644 --- a/src/containers/RotationForm/RotationForm.tsx +++ b/src/containers/RotationForm/RotationForm.tsx @@ -202,9 +202,11 @@ export const RotationForm = observer((props: RotationFormProps) => { } }; - const onError = useCallback((error) => { - setErrors(error.response.data); - }, []); + const onError = (error) => { + if (error.response?.data) { + setErrors(error.response.data); + } + }; const handleChange = useDebouncedCallback(updatePreview, 200); diff --git a/src/containers/UsersTimezones/ScheduleUserDetails/ScheduleUserDetails.tsx b/src/containers/UsersTimezones/ScheduleUserDetails/ScheduleUserDetails.tsx index 6cecdf006d..2cdf394a03 100644 --- a/src/containers/UsersTimezones/ScheduleUserDetails/ScheduleUserDetails.tsx +++ b/src/containers/UsersTimezones/ScheduleUserDetails/ScheduleUserDetails.tsx @@ -43,7 +43,7 @@ export const ScheduleUserDetails: FC = observer((props const { organizationStore } = store; const slackWorkspaceName = - organizationStore.currentOrganization.slack_team_identity?.cached_name?.replace(/[^0-9a-z]/gi, '') || ''; + organizationStore.currentOrganization?.slack_team_identity?.cached_name?.replace(/[^0-9a-z]/gi, '') || ''; return (
diff --git a/src/models/escalation_chain/escalation_chain.ts b/src/models/escalation_chain/escalation_chain.ts index 0efd785d88..e3da76f844 100644 --- a/src/models/escalation_chain/escalation_chain.ts +++ b/src/models/escalation_chain/escalation_chain.ts @@ -86,7 +86,7 @@ export class EscalationChainStore extends BaseStore { try { escalationChain = await this.getById(id, skipErrorHandling); } catch (error) { - if (error.response.data.error_code === 'wrong_team') { + if (error.response.data?.error_code === 'wrong_team') { escalationChain = { id, name: '🔒 Private escalation chain', diff --git a/src/models/label/label.helpers.ts b/src/models/label/label.helpers.ts index 0e9e174417..a0c8f1d2cb 100644 --- a/src/models/label/label.helpers.ts +++ b/src/models/label/label.helpers.ts @@ -1,7 +1,7 @@ import { ApiSchemas } from 'network/oncall-api/api.types'; export const splitToGroups = (labels: Array | Array) => { - return labels.reduce( + return labels?.reduce( (memo, option) => { memo.find(({ name }) => name === (option.prescribed ? 'System' : 'User added')).options.push(option); diff --git a/src/models/schedule/schedule.ts b/src/models/schedule/schedule.ts index ded9afaa47..cf84a325c1 100644 --- a/src/models/schedule/schedule.ts +++ b/src/models/schedule/schedule.ts @@ -189,7 +189,7 @@ export class ScheduleStore extends BaseStore { try { schedule = await this.getById(id, true, fromOrganization); } catch (error) { - if (error.response.data.error_code === 'wrong_team') { + if (error.response.data?.error_code === 'wrong_team') { schedule = { id, name: '🔒 Private schedule', diff --git a/src/pages/settings/tabs/ChatOps/tabs/SlackSettings/SlackSettings.tsx b/src/pages/settings/tabs/ChatOps/tabs/SlackSettings/SlackSettings.tsx index ca86e98f12..13915572f6 100644 --- a/src/pages/settings/tabs/ChatOps/tabs/SlackSettings/SlackSettings.tsx +++ b/src/pages/settings/tabs/ChatOps/tabs/SlackSettings/SlackSettings.tsx @@ -118,7 +118,7 @@ class _SlackSettings extends Component {
Slack App settings - + { ); }; - renderSlackWorkspace = () => { - const { store } = this.props; - return {store.organizationStore.currentOrganization.slack_team_identity?.cached_name}; - }; - - renderSlackChannels = () => { - const { - store: { organizationStore, slackChannelStore }, - } = this.props; - return ( - - - className={cx('select', 'control')} - items={slackChannelStore.items} - fetchItemsFn={slackChannelStore.updateItems} - fetchItemFn={slackChannelStore.updateItem} - getSearchResult={slackChannelStore.getSearchResult} - displayField="display_name" - valueField="id" - placeholder="Select Slack Channel" - value={organizationStore.currentOrganization?.slack_channel?.id} - onChange={this.handleSlackChannelChange} - nullItemName={PRIVATE_CHANNEL_NAME} - /> - - ); - }; - removeSlackIntegration = async () => { const { store } = this.props; try { diff --git a/src/pages/users/Users.tsx b/src/pages/users/Users.tsx index 6aee6579fb..ed9c981779 100644 --- a/src/pages/users/Users.tsx +++ b/src/pages/users/Users.tsx @@ -367,7 +367,7 @@ class Users extends React.Component { warnings.push('Phone not verified'); } - if (organizationStore.currentOrganization.slack_team_identity && !user.slack_user_identity) { + if (organizationStore.currentOrganization?.slack_team_identity && !user.slack_user_identity) { warnings.push('Slack profile is not connected'); } diff --git a/src/utils/faro.ts b/src/utils/faro.ts index 6b0bd43e22..3d91a0020a 100644 --- a/src/utils/faro.ts +++ b/src/utils/faro.ts @@ -99,17 +99,17 @@ class BaseFaroHelper { pushAxiosNetworkResponseEvent = ({ name, res }: { name: string; res: AxiosResponse }) => { this.faro?.api.pushEvent(name, { - url: res.config.url, + url: res.config?.url, status: `${res.status}`, statusText: `${res.statusText}`, - method: res.config.method.toUpperCase(), + method: res.config?.method.toUpperCase(), }); }; pushAxiosNetworkError = (res: AxiosResponse) => { this.faro?.api.pushError(new Error(`Network error: ${res.status}`), { context: { - url: res.config.url, + url: res.config?.url, type: 'network', data: `${safeJSONStringify(res.data)}`, status: `${res.status}`,