Fix ScheduleEdit page not working directly by url (#3477)

This commit is contained in:
Linux123123 2021-08-03 06:07:39 +03:00 committed by GitHub
parent e8746feb97
commit 9c64fb29a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 9 deletions

View File

@ -58,7 +58,7 @@ export default () => {
css={tw`cursor-pointer mb-2 flex-wrap`} css={tw`cursor-pointer mb-2 flex-wrap`}
onClick={(e: any) => { onClick={(e: any) => {
e.preventDefault(); e.preventDefault();
history.push(`${match.url}/${schedule.id}`, { schedule }); history.push(`${match.url}/${schedule.id}`);
}} }}
> >
<ScheduleRow schedule={schedule}/> <ScheduleRow schedule={schedule}/>

View File

@ -1,6 +1,5 @@
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { useHistory, useLocation, useParams } from 'react-router-dom'; import { useHistory, useParams } from 'react-router-dom';
import { Schedule } from '@/api/server/schedules/getServerSchedules';
import getServerSchedule from '@/api/server/schedules/getServerSchedule'; import getServerSchedule from '@/api/server/schedules/getServerSchedule';
import Spinner from '@/components/elements/Spinner'; import Spinner from '@/components/elements/Spinner';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';
@ -23,10 +22,6 @@ interface Params {
id: string; id: string;
} }
interface State {
schedule?: Schedule;
}
const CronBox = ({ title, value }: { title: string; value: string }) => ( const CronBox = ({ title, value }: { title: string; value: string }) => (
<div css={tw`bg-neutral-700 rounded p-3`}> <div css={tw`bg-neutral-700 rounded p-3`}>
<p css={tw`text-neutral-300 text-sm`}>{title}</p> <p css={tw`text-neutral-300 text-sm`}>{title}</p>
@ -47,7 +42,6 @@ const ActivePill = ({ active }: { active: boolean }) => (
export default () => { export default () => {
const history = useHistory(); const history = useHistory();
const { state } = useLocation<State>();
const { id: scheduleId } = useParams<Params>(); const { id: scheduleId } = useParams<Params>();
const id = ServerContext.useStoreState(state => state.server.data!.id); const id = ServerContext.useStoreState(state => state.server.data!.id);
@ -57,7 +51,7 @@ export default () => {
const [ isLoading, setIsLoading ] = useState(true); const [ isLoading, setIsLoading ] = useState(true);
const [ showEditModal, setShowEditModal ] = useState(false); const [ showEditModal, setShowEditModal ] = useState(false);
const schedule = ServerContext.useStoreState(st => st.schedules.data.find(s => s.id === state.schedule?.id), isEqual); const schedule = ServerContext.useStoreState(st => st.schedules.data.find(s => s.id === Number(scheduleId)), isEqual);
const appendSchedule = ServerContext.useStoreActions(actions => actions.schedules.appendSchedule); const appendSchedule = ServerContext.useStoreActions(actions => actions.schedules.appendSchedule);
useEffect(() => { useEffect(() => {