Commit b23f651b authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

[client] Forbid some invalid history transitions

It shouldn't be possible to move from the "create transaction" page, or
the "budget" page, to the same page but for a non-account view.
parent 866bea44
Pipeline #407763 passed with stage
in 3 minutes and 45 seconds
......@@ -22,6 +22,7 @@ import ValidatedTextInput from '../ui/validated-text-input';
import { BackLink, Form } from '../ui';
import { ViewContext } from '../drivers';
import { useHistory } from 'react-router-dom';
import { RedirectIfNotAccount } from '../../main';
const CreateTransaction = () => {
const history = useHistory();
......@@ -122,4 +123,10 @@ const CreateTransaction = () => {
CreateTransaction.displayName = 'CreateTransaction';
export default CreateTransaction;
export default () => {
return (
<RedirectIfNotAccount>
<CreateTransaction />
</RedirectIfNotAccount>
);
};
......@@ -78,7 +78,7 @@ const RedirectIfUnknownAccount = (props: { children: React.ReactNode | React.Rea
return <>{props.children}</>;
};
const RedirectIfNotAccount = (props: { children: React.ReactNode | React.ReactNode[] }) => {
export const RedirectIfNotAccount = (props: { children: React.ReactNode | React.ReactNode[] }) => {
const view = useContext(ViewContext);
if (view.driver.type !== DriverType.Account) {
return <Redirect to={URL.reports.url(view.driver)} push={false} />;
......@@ -111,9 +111,11 @@ const View = () => {
</RedirectIfUnknownAccount>
</Route>
<Route path={URL.budgets.pattern}>
<RedirectIfUnknownAccount>
<Budget />
</RedirectIfUnknownAccount>
<RedirectIfNotAccount>
<RedirectIfUnknownAccount>
<Budget />
</RedirectIfUnknownAccount>
</RedirectIfNotAccount>
</Route>
<Route path={URL.charts.pattern}>
<RedirectIfUnknownAccount>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment