generated from ocadotechnology/codeforlife-template-frontend
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as forms from "codeforlife/components/form" | ||
import * as pages from "codeforlife/components/page" | ||
import * as yup from "yup" | ||
import { Typography } from "@mui/material" | ||
// eslint-disable-next-line sort-imports | ||
import { type FC } from "react" | ||
import { Link } from "codeforlife/components/router" | ||
import { handleQueryState } from "codeforlife/utils/api" | ||
import { useParamsRequired } from "codeforlife/hooks" | ||
// eslint-disable-next-line sort-imports | ||
import { useLazyRetrieveContributorQuery } from "../../api/contributor" | ||
// eslint-disable-next-line sort-imports | ||
import { paths } from "../../routes" | ||
|
||
export interface ContributorDetailProps {} | ||
|
||
const ContributorDetail: FC<ContributorDetailProps> = () => { | ||
const [retrieveContributor, retrieveContributorResult] = | ||
useLazyRetrieveContributorQuery() | ||
|
||
return useParamsRequired({ | ||
shape: { id: yup.number().required().min(1) }, | ||
children: () => | ||
handleQueryState(retrieveContributorResult, contributor => ( | ||
<pages.Page> | ||
<pages.Section> | ||
<Typography variant="h1">Update fruit</Typography> | ||
<forms.Form | ||
initialValues={contributor} | ||
onSubmit={alert} | ||
></forms.Form> | ||
</pages.Section> | ||
<pages.Section> | ||
<Link className="back-to" to={paths.contributors._}> | ||
Contributor list | ||
</Link> | ||
</pages.Section> | ||
</pages.Page> | ||
)), | ||
onValidationSuccess: params => { | ||
void retrieveContributor(params.id, true) | ||
}, | ||
onValidationError: navigate => { | ||
navigate(paths.contributors._, { | ||
state: { | ||
notifications: [ | ||
{ props: { error: true, children: "Failed to get params" } }, | ||
], | ||
}, | ||
}) | ||
}, | ||
}) | ||
} | ||
|
||
export default ContributorDetail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as pages from "codeforlife/components/page" | ||
import { Stack, Typography } from "@mui/material" | ||
import { type FC } from "react" | ||
import { LinkIconButton } from "codeforlife/components/router" | ||
import { TablePagination } from "codeforlife/components" | ||
import { generatePath } from "react-router" | ||
import { paths } from "../../routes" | ||
import { useLazyListContributorsQuery } from "../../api/contributor" | ||
|
||
export interface ContributorListProps {} | ||
|
||
const ContributorList: FC<ContributorListProps> = () => { | ||
return ( | ||
<pages.Page> | ||
<pages.Section> | ||
<Typography fontWeight="bold">Helllllloooo </Typography> | ||
<TablePagination | ||
useLazyListQuery={useLazyListContributorsQuery} | ||
preferCacheValue | ||
> | ||
{contributors => | ||
contributors.map(contributor => ( | ||
<Stack direction="row" key={contributor.id} gap={5}> | ||
<Typography fontWeight="bold">{contributor.id}</Typography> | ||
<Typography> | ||
{contributor.name} ({contributor.email}) | ||
</Typography> | ||
|
||
<LinkIconButton | ||
to={generatePath(paths.contributors.id._, { | ||
id: contributor.id, | ||
})} | ||
></LinkIconButton> | ||
</Stack> | ||
)) | ||
} | ||
</TablePagination> | ||
</pages.Section> | ||
</pages.Page> | ||
) | ||
} | ||
|
||
export default ContributorList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Route } from "react-router-dom" | ||
|
||
import ContributorDetail from "../pages/contributorDetail/ContributorDetail" | ||
import ContributorList from "../pages/contributorList/ContributorList" | ||
import paths from "./paths" | ||
|
||
const fruit = ( | ||
<> | ||
<Route path={paths.contributors.id._} element={<ContributorDetail />} /> | ||
<Route path={paths.contributors._} element={<ContributorList />} /> | ||
</> | ||
) | ||
|
||
export default fruit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters