Create/Edit pack UX: Pack save redirects to manage packs page, fix flash message (#2767)

This commit is contained in:
RachelElysia 2021-11-08 10:18:36 -08:00 committed by GitHub
parent d0777ccfd3
commit ed2a9abd9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 21 deletions

View file

@ -0,0 +1 @@
* Saving a pack redirects to the Manage Packs Page, fix flash render after creating pack

View file

@ -36,6 +36,7 @@ import PackQueryEditorModal from "./components/PackQueryEditorModal";
import RemovePackQueryModal from "./components/RemovePackQueryModal";
interface IEditPacksPageProps {
router: any;
params: Params;
}
@ -71,6 +72,7 @@ interface IFormData {
const baseClass = "edit-pack-page";
const EditPacksPage = ({
router,
params: { id: paramsPackId },
}: IEditPacksPageProps): JSX.Element => {
const { isPremiumTier } = useContext(AppContext);
@ -102,13 +104,13 @@ const EditPacksPage = ({
}
);
const { data: storedPack, refetch: refetchStoredPack } = useQuery<
IStoredPackResponse,
Error,
IPack
>(["stored pack"], () => packsAPI.load(packId), {
select: (data: IStoredPackResponse) => data.pack,
});
const { data: storedPack } = useQuery<IStoredPackResponse, Error, IPack>(
["stored pack"],
() => packsAPI.load(packId),
{
select: (data: IStoredPackResponse) => data.pack,
}
);
const {
data: storedPackQueries,
@ -226,8 +228,7 @@ const EditPacksPage = ({
packsAPI
.update(packId, updatedPack)
.then(() => {
refetchStoredPack();
window.scrollTo(0, 0);
router.push(PATHS.MANAGE_PACKS);
dispatch(renderFlash("success", `Successfully updated this pack.`));
})
.catch((response) => {

View file

@ -41,25 +41,20 @@ export class PackComposerPage extends Component {
return false;
};
visitPackPage = (packID) => {
const { dispatch } = this.props;
dispatch(push(PATHS.PACK(packID)));
return false;
};
handleSubmit = (formData) => {
const { create } = packActions;
const { dispatch } = this.props;
const { visitPackPage } = this;
return dispatch(create(formData))
.then((pack) => {
const { id: packID } = pack;
dispatch(renderFlash("success", `Pack successfully created.`));
visitPackPage(packID);
dispatch(push(PATHS.PACK(packID)));
dispatch(
renderFlash(
"success",
"Pack successfully created. Add queries to your pack."
)
);
})
.catch((response) => {
if (response.base.slice(0, 27) === "Error 1062: Duplicate entry") {