Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling fix/dsc-namespace into develop #668

Merged
merged 25 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2282a0b
refactor(HeaderRow.tsx): extract container styles into makeStyles hoo…
ktun95 Feb 28, 2024
65e1fb9
refactor(namespace.ts): change NAMESPACE value from "dsc" to "stockce…
ktun95 Feb 28, 2024
dcfd676
refactor(ContentView.tsx): remove unused import and container component
ktun95 Feb 28, 2024
373c6e6
refactor(EditView.tsx): remove unused import and unnecessary wrapping…
ktun95 Feb 28, 2024
c7b2064
refactor(EditableView.tsx): remove unused import and replace Containe…
ktun95 Feb 28, 2024
f7119ec
refactor(AddPageView.tsx): remove unnecessary Container component
ktun95 Feb 28, 2024
e2fbe33
feat(index.tsx): move home page
ktun95 Feb 28, 2024
5e92571
feat(index.tsx): add dynamic content rendering based on GraphQL query…
ktun95 Feb 28, 2024
43f4218
feat(index.tsx): add import statement for ACCESS constant from "auth"…
ktun95 Feb 28, 2024
223c3d5
feat(editable.tsx): add new editable component for the homepage
ktun95 Feb 28, 2024
6b10bb9
feat(edit.tsx): add new EditHomepage component for editing the homepa…
ktun95 Feb 28, 2024
912ed39
refactor(edit.tsx): refactor code to use the useTokenAndUser hook for…
ktun95 Feb 28, 2024
53e0a74
feat(auth): add useTokenAndUser hook to handle token and user data re…
ktun95 Feb 28, 2024
91c4a06
refactor(EditablePages/Edit.tsx): refactor code to use the useTokenAn…
ktun95 Feb 28, 2024
f97c76d
fix(Editor.tsx): change height CSS property to maxHeight for the edit…
ktun95 Feb 28, 2024
a64cc7d
chore(authNavbarData.json): update link for "Stock Center Home" item …
ktun95 Feb 28, 2024
ff55c27
feat(show.tsx): add ShowHomepage component for the main homepage of DSC
ktun95 Feb 28, 2024
5fd4683
fix(editable.tsx): import OtherError component from "@dictybase/ui-co…
ktun95 Feb 28, 2024
4aa4283
fix(edit.tsx): import OtherError component from "@dictybase/ui-common…
ktun95 Feb 28, 2024
8281570
refactor(addpage.tsx): refactor code to use the useTokenAndUser hook …
ktun95 Feb 28, 2024
4c82f65
refactor(AddPage.tsx): refactor AddPage component to use custom hook …
ktun95 Feb 28, 2024
65b82a0
chore(FrontPageApp.tsx): change maxWidth value from "xl" to "lg" for …
ktun95 Feb 28, 2024
c39445a
refactor(index): simplify error handling in EditHomepage, EditableHom…
ktun95 Feb 28, 2024
0c58a2e
feat(index): add isAuthorized prop to CatalogLinks component in EditH…
ktun95 Feb 28, 2024
a2e6c44
chore(home/edit.tsx, home/editable.tsx): remove unused components and…
ktun95 Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dicty-frontpage/src/app/layout/FrontPageApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const FrontPageApp = () => {
<HeaderWithAuth clientRouter={frontpageRouter} />
<NavbarWithAuth theme={navTheme} />
<main className={classes.main}>
<Container maxWidth="xl">
<Container maxWidth="lg">
<ErrorBoundary>
<RouterProvider router={frontpageRouter} />
</ErrorBoundary>
Expand Down
23 changes: 4 additions & 19 deletions apps/dicty-frontpage/src/features/EditablePages/AddPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Navigate } from "react-router-dom"
import { useState, useEffect } from "react"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { type UserInfoResponse, useLogto } from "@logto/react"
import { match, P } from "ts-pattern"
import {
AddPageView,
FullPageLoadingDisplay,
contentPageErrorMatcher,
} from "@dictybase/ui-common"
import { useTokenAndUser } from "auth"
import { NAMESPACE } from "../../common/constants/namespace"
import { useSlug } from "../../common/hooks/useSlug"
import { useContentPath } from "../../common/hooks/useContentPath"
Expand All @@ -20,23 +19,9 @@ const AddPage = () => {
errorPolicy: "all",
fetchPolicy: "network-only",
})
const { fetchUserInfo, getAccessToken, isAuthenticated } = useLogto()
const [token, setToken] = useState<string>()
const [user, setUser] = useState<UserInfoResponse>()
useEffect(() => {
const getUserData = async () => {
if (!isAuthenticated) return
setToken(
await getAccessToken(
import.meta.env.VITE_APP_LOGTO_API_SECOND_RESOURCE,
),
)
setUser(await fetchUserInfo())
}

getUserData()
}, [fetchUserInfo, getAccessToken, isAuthenticated])

const { token, user } = useTokenAndUser(
import.meta.env.VITE_APP_LOGTO_API_SECOND_RESOURCE,
)
return match({
token,
user,
Expand Down
22 changes: 4 additions & 18 deletions apps/dicty-frontpage/src/features/EditablePages/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Navigate } from "react-router-dom"
import { useState, useEffect } from "react"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { type UserInfoResponse, useLogto } from "@logto/react"
import {
EditView,
FullPageLoadingDisplay,
contentPageErrorMatcher,
} from "@dictybase/ui-common"
import { match, P } from "ts-pattern"
import { useTokenAndUser } from "auth"
import { NAMESPACE } from "../../common/constants/namespace"
import { useSlug } from "../../common/hooks/useSlug"

Expand All @@ -17,22 +16,9 @@ const Edit = () => {
variables: { slug: `${NAMESPACE}-${slug}` },
errorPolicy: "all",
})
const { fetchUserInfo, getAccessToken, isAuthenticated } = useLogto()
const [token, setToken] = useState<string>()
const [user, setUser] = useState<UserInfoResponse>()
useEffect(() => {
const getUserData = async () => {
if (!isAuthenticated) return
setToken(
await getAccessToken(
import.meta.env.VITE_APP_LOGTO_API_SECOND_RESOURCE,
),
)
setUser(await fetchUserInfo())
}

getUserData()
}, [fetchUserInfo, getAccessToken, isAuthenticated])
const { token, user } = useTokenAndUser(
import.meta.env.VITE_APP_LOGTO_API_SECOND_RESOURCE,
)

return match({
token,
Expand Down
16 changes: 13 additions & 3 deletions apps/stock-center/src/components/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import Grid from "@material-ui/core/Grid"
import { Grid, makeStyles } from "@material-ui/core"
import { CartIcon } from "@dictybase/ui-dsc"
import { useAtomValue } from "jotai"
import { Outlet } from "react-router-dom"
import { Breadcrumbs } from "./Breadcrumbs"
import { isFullAtom, strainItemsAtom } from "../state"

const useStyles = makeStyles({
container: {
marginBottom: "1rem",
},
})
/**
* This is the cart component that displays between the Navbar and body content on every page.
* It has a cart icon with the current number of added items next to it.
*/

const HeaderRow = () => {
const isFull = useAtomValue(isFullAtom)
const strainItems = useAtomValue(strainItemsAtom)
const { container } = useStyles()

return (
<>
<Grid container justifyContent="space-between" alignItems="center">
<Grid
container
justifyContent="space-between"
alignItems="center"
className={container}>
<Grid item>
<Breadcrumbs />
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion apps/stock-center/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const NAMESPACE = "dsc"
const NAMESPACE = "stockcenter"

export { NAMESPACE }
44 changes: 0 additions & 44 deletions apps/stock-center/src/pages/home/edit.tsx

This file was deleted.

56 changes: 0 additions & 56 deletions apps/stock-center/src/pages/home/editable.tsx

This file was deleted.

36 changes: 0 additions & 36 deletions apps/stock-center/src/pages/index.tsx

This file was deleted.

62 changes: 62 additions & 0 deletions apps/stock-center/src/pages/index/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Grid from "@material-ui/core/Grid"
import {
useStyles,
Title,
Heading,
Slide,
CatalogLinks,
FileLinks,
} from "@dictybase/ui-dsc"
import { EditView, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { match, P } from "ts-pattern"
import { ACCESS, useTokenAndUser } from "auth"
import { NAMESPACE } from "../../namespace"
/**
* Homepage is the main homepage component for DSC.
*/
const EditHomepage = () => {
const result = useContentBySlugQuery({
variables: { slug: `${NAMESPACE}-intro` },
})
const { token, user } = useTokenAndUser(
import.meta.env.VITE_APP_LOGTO_API_SECOND_RESOURCE,
)
const classes = useStyles({})
return (
<>
<Title />
<Grid container justifyContent="space-between" spacing={3}>
<Heading />
<Grid item xs={12} className={classes.intro}>
{match({ ...result })
.with(
{ data: { contentBySlug: P.select({ content: P.string }) } },
(content) => (
<EditView
data={content}
userId={user?.email as string}
token={token as string}
/>
),
)
.with({ loading: true }, () => <LoadingDisplay rows={4} />)
.with({ error: P.not(undefined) }, () => <OtherError />)
.otherwise(() => (
<> This message should not appear. </>
))}
</Grid>
<Grid container item xs={12} spacing={4} justifyContent="flex-start">
<Slide />
<CatalogLinks isAuthorized />
<FileLinks />
</Grid>
</Grid>
</>
)
}

// eslint-disable-next-line import/no-default-export
export default EditHomepage
export const access = ACCESS.private
export const roles = ["content-admin"]
54 changes: 54 additions & 0 deletions apps/stock-center/src/pages/index/editable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Grid from "@material-ui/core/Grid"
import {
useStyles,
Title,
Heading,
Slide,
CatalogLinks,
FileLinks,
} from "@dictybase/ui-dsc"
import { EditableView, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { match, P } from "ts-pattern"
import { ACCESS } from "auth"
import { NAMESPACE } from "../../namespace"
/**
* Homepage is the main homepage component for DSC.
*/
const EditableHomepage = () => {
const result = useContentBySlugQuery({
variables: { slug: `${NAMESPACE}-intro` },
})

const classes = useStyles({})
return (
<>
<Title />
<Grid container justifyContent="space-between" spacing={3}>
<Heading />
<Grid item xs={12} className={classes.intro}>
{match(result)
.with(
{ data: { contentBySlug: P.select({ content: P.string }) } },
(content) => <EditableView data={content} />,
)
.with({ loading: true }, () => <LoadingDisplay rows={4} />)
.with({ error: P.not(undefined) }, () => <OtherError />)
.otherwise(() => (
<> This message should not appear. </>
))}
</Grid>
<Grid container item xs={12} spacing={4} justifyContent="flex-start">
<Slide />
<CatalogLinks isAuthorized />
<FileLinks />
</Grid>
</Grid>
</>
)
}

// eslint-disable-next-line import/no-default-export
export default EditableHomepage
export const access = ACCESS.private
export const roles = ["content-admin"]
Loading
Loading