Skip to content

Commit

Permalink
client: Add toast for edit notification channel popup
Browse files Browse the repository at this point in the history
  • Loading branch information
XxRoloxX committed Nov 30, 2024
1 parent bb6108a commit 3e33d28
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import LabelInput, {
import NewChannelPopupHeader from 'pages/Notification/NewChannelPopupHeader/NewChannelPopupHeader';
import { EditChannelPopupProps } from './EditChannelPopup';
import { discordWebhookValidation } from 'lib/validators';
import { useToast } from 'providers/ToastProvider/ToastProvider';

interface EditDiscordChannelPopupProps extends EditChannelPopupProps {
id: string;
Expand All @@ -37,6 +38,8 @@ const EditDiscordChannelPopup = ({
webhookUrl: '',
});

const { showMessage } = useToast();

const editDiscordChannel = async () => {
if (
discordChannel.name === name &&
Expand All @@ -46,12 +49,14 @@ const EditDiscordChannelPopup = ({

try {
await ManagmentServiceApiInstance.editDiscordChannel(discordChannel);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error posting slack channels: ', error);
} finally {
setIsDisplayed(false);
onSubmit();
showMessage({ message: 'Channel was updated', type: 'INFO' });
} catch (error) {
showMessage({
message: `Failed to update channel ${error}`,
type: 'ERROR',
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import LabelInput, {
import NewChannelPopupHeader from 'pages/Notification/NewChannelPopupHeader/NewChannelPopupHeader';
import { EditChannelPopupProps } from './EditChannelPopup';
import { emailValidation } from 'lib/validators';
import { useToast } from 'providers/ToastProvider/ToastProvider';

interface EditEmailChannelPopupProps extends EditChannelPopupProps {
id: string;
Expand All @@ -36,18 +37,24 @@ const EditEmailChannelPopup = ({
name,
email,
});
const { showMessage } = useToast();

const editEmailChannel = async () => {
if (emailChannel.name === name && emailChannel.email === email) return;

try {
await ManagmentServiceApiInstance.editEmailChannel(emailChannel);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error posting slack channels: ', error);
} finally {
showMessage({
message: 'Channel updated successfully',
type: 'INFO',
});
onSubmit();
setIsDisplayed(false);
} catch (error) {
showMessage({
message: `Failed to update channel ${error}`,
type: 'ERROR',
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import LabelInput, {
import NewChannelPopupHeader from 'pages/Notification/NewChannelPopupHeader/NewChannelPopupHeader';
import { EditChannelPopupProps } from './EditChannelPopup';
import { slackWebhookValidation } from 'lib/validators';
import { useToast } from 'providers/ToastProvider/ToastProvider';

interface EditSlackChannelPopupProps extends EditChannelPopupProps {
id: string;
Expand All @@ -37,18 +38,25 @@ const EditSlackChannelPopup = ({
webhookUrl: '',
});

const { showMessage } = useToast();

const editSlackChannel = async () => {
if (slackChannel.name === name && slackChannel.webhookUrl === webhookUrl)
return;

try {
await ManagmentServiceApiInstance.editSlackChannel(slackChannel);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error posting slack channels: ', error);
} finally {
showMessage({
message: 'Channel updated successfully',
type: 'INFO',
});
onSubmit();
setIsDisplayed(false);
} catch (error) {
showMessage({
message: `Failed to update channel ${error}`,
type: 'ERROR',
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const DiscordTable = () => {
try {
await ManagmentServiceApiInstance.testDiscordChannel(props.id);
showMessage({
message: 'Test notification was sent',
message: 'Successfully sent a test notification',
type: 'INFO',
});
} catch (e: unknown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const EmailTable = () => {
try {
await ManagmentServiceApiInstance.testEmailChannel(props.id);
showMessage({
message: 'Test notification was sent',
message: 'Successfully sent a test notification',
type: 'INFO',
});
} catch (e: unknown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const SlackTable = () => {
try {
await ManagmentServiceApiInstance.testSlackChannel(props.id);
showMessage({
message: 'Test notification was sent',
message: 'Successfully sent a test notification',
type: 'INFO',
});
} catch (e: unknown) {
Expand Down

0 comments on commit 3e33d28

Please sign in to comment.