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

feat: implement widgets #1282

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ app.use((request, response) => {
return handler(request, response, {
public: './dist',
rewrites: [{ source: '*', destination: '/index.html' }],
headers: [
{
source: '/widgets/**',
headers: [
{
key: 'Access-Control-Allow-Origin',
value: '*',
},
],
},
],
})
})

Expand Down
38 changes: 32 additions & 6 deletions src/config/routes/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ProfilePage = () => import('../../pages/profile/Profile')
const Badges = () => import('../../pages/badges/BadgesPage')
const Landing = () => import('../../pages/landing')
const AboutPage = () => import('../../pages/about/About')
const Widgets = () => import('../../pages/widgets')

export const platformRoutes: RouteObject[] = [
{
Expand Down Expand Up @@ -316,7 +317,7 @@ export const platformRoutes: RouteObject[] = [
path: getPath('projectManageRewards', PathName.projectId),
async lazy() {
const ProjectManageRewards = await Project().then(
(m) => m.ProjectManageRewards,
(m) => m.ProjectManageRewards,
)
return {
element: renderPrivateRoute(ProjectManageRewards),
Expand All @@ -326,18 +327,24 @@ export const platformRoutes: RouteObject[] = [
{
path: getPath('projectCreateReward', PathName.projectId),
async lazy() {
const ProjectCreateReward = await Project()
.then((m) => m.ProjectCreateReward)
const ProjectCreateReward = await Project().then(
(m) => m.ProjectCreateReward,
)
return {
element: renderPrivateRoute(ProjectCreateReward),
}
},
},
{
path: getPath('projectEditReward', PathName.projectId, PathName.rewardId),
path: getPath(
'projectEditReward',
PathName.projectId,
PathName.rewardId,
),
async lazy() {
const ProjectEditReward = await Project()
.then((m) => m.ProjectEditReward)
const ProjectEditReward = await Project().then(
(m) => m.ProjectEditReward,
)
return {
element: renderPrivateRoute(ProjectEditReward),
}
Expand Down Expand Up @@ -443,6 +450,16 @@ export const platformRoutes: RouteObject[] = [
},
]

export const widgetsRoutesV1: RouteObject[] = [
{
path: '/widgets/v1/link-to-project/:projectId',
async lazy() {
const LinkToProject = await Widgets().then((m) => m.LinkToProject)
return { Component: LinkToProject }
},
},
]

export const router = createBrowserRouter([
{
path: '/',
Expand All @@ -455,6 +472,15 @@ export const router = createBrowserRouter([
ErrorBoundary,
// ,
},
{
path: '/widgets',
children: [
{
path: '/widgets/v1',
children: widgetsRoutesV1,
},
],
},
],
},
])
1 change: 1 addition & 0 deletions src/pages/widgets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './linkToProject'
25 changes: 25 additions & 0 deletions src/pages/widgets/linkToProject/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useParams } from 'react-router-dom'

import { useColorMode } from '@chakra-ui/react'
import { useEffect } from 'react'
import { ButtonComponent } from '../../../components/ui'

export const LinkToProject = () => {
document.documentElement.style.background = 'transparent'
document.body.style.background = 'transparent'

const { projectId } = useParams()
const { colorMode, toggleColorMode } = useColorMode()

useEffect(() => {
colorMode === 'dark' && toggleColorMode()
}, [toggleColorMode, colorMode])

return (
<div>
<ButtonComponent as="a" href={`/project/${projectId}`} primary>
Go to project
</ButtonComponent>
</div>
)
}