Skip to content

Commit

Permalink
Redirect the user after creating a new announcement
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Mar 11, 2023
1 parent 685cc1c commit a443bf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/flat-emus-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@k-phoen/backstage-plugin-announcements': patch
---

Redirect the user after creating a new announcement
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { ReactNode } from 'react';
import { useNavigate } from 'react-router-dom';
import { Page, Header, Content } from '@backstage/core-components';
import { alertApiRef, useApi } from '@backstage/core-plugin-api';
import { alertApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api';
import { announcementsApiRef, CreateAnnouncementRequest } from '../../api';
import { rootRouteRef } from '../../routes';
import { AnnouncementForm } from '../AnnouncementForm';

type CreateAnnouncementPageProps = {
Expand All @@ -12,12 +14,16 @@ type CreateAnnouncementPageProps = {

export const CreateAnnouncementPage = (props: CreateAnnouncementPageProps) => {
const announcementsApi = useApi(announcementsApiRef);
const rootPage = useRouteRef(rootRouteRef);
const alertApi = useApi(alertApiRef);
const navigate = useNavigate();

const onSubmit = async (request: CreateAnnouncementRequest) => {
try {
await announcementsApi.createAnnouncement(request);
alertApi.post({ message: 'Announcement created.', severity: 'success' });

navigate(rootPage());
} catch (err) {
alertApi.post({ message: (err as Error).message, severity: 'error' });
}
Expand Down

0 comments on commit a443bf3

Please sign in to comment.