Skip to content

Commit

Permalink
fix accounts/new route (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr authored Jul 28, 2023
1 parent 6cb88e9 commit ddcce58
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions app/src/accounts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ export default function accounts(
},
index: true,
},
{
path: "new",
element: <AccountForm />,
async action({ request }) {
let data = Object.fromEntries(await request.formData());
switch (request.method) {
case "POST":
const account = await apiClient.createAccount(
data as unknown as PartialAccount
);
return redirect(`/accounts/${account.id}`);
default:
throw new Error(`unexpected method ${request.method}`);
}
},
},

{
path: ":account_id",
id: "account",
Expand Down Expand Up @@ -52,27 +69,7 @@ export default function accounts(
);
},
children: [
{
path: "",
element: <AccountSummary />,
},
{
path: "new",
element: <AccountForm />,
async action({ request }) {
let data = Object.fromEntries(await request.formData());
switch (request.method) {
case "POST":
const account = await apiClient.createAccount(
data as unknown as PartialAccount
);
return redirect(`/accounts/${account.id}`);
default:
throw new Error(`unexpected method ${request.method}`);
}
},
},

{ element: <AccountSummary />, path: "", index: true },
...children,
],
},
Expand Down

0 comments on commit ddcce58

Please sign in to comment.