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

Allow funder to login from funding flow #859

Merged
Merged
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
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-unused-vars': 0,
'react-hooks/exhaustive-deps': 0,
'react-hooks/exhaustive-deps': 1,
'@typescript-eslint/ban-types': 0,
'object-curly-spacing': 0,
'no-negated-condition': 0,
Expand Down
22 changes: 22 additions & 0 deletions src/components/icons/svg/ProjectIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Icon, IconProps } from '@chakra-ui/react'

export const ProjectIcon = (props: IconProps) => {
return (
<Icon
width="28px"
height="29px"
viewBox="0 0 28 29"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M27 25.3331V14.8969C27 13.4299 26.411 12.0277 25.3715 11.0202L15.7858 1.72856C14.7836 0.757146 13.2164 0.757146 12.2142 1.72856L2.62844 11.0202C1.589 12.0277 1 13.4299 1 14.8969V25.3331C1 26.806 2.16406 28 3.6 28H24.4C25.836 28 27 26.806 27 25.3331Z"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</Icon>
)
}
60 changes: 29 additions & 31 deletions src/components/layouts/CardLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Stack, StackProps } from '@chakra-ui/react'
import { forwardRef } from 'react'
import { Link, LinkProps } from 'react-router-dom'

export interface CardLayoutProps
Expand All @@ -9,34 +10,31 @@ export interface CardLayoutProps
click?: boolean
}

export const CardLayout = ({
children,
noborder,
click,
hover,
...rest
}: CardLayoutProps) => {
return (
<Stack
as={rest.to ? Link : undefined}
tabIndex={-1}
overflow={'hidden'}
backgroundColor="white"
border="2px solid"
borderColor={noborder ? 'transparent' : 'brand.neutral200'}
borderRadius="8px"
boxShadow="none"
padding="24px"
spacing="10px"
_hover={
hover ? { cursor: 'pointer', borderColor: 'brand.neutral400' } : {}
}
_active={click ? { borderColor: 'brand.primary' } : {}}
_focus={click ? { borderColor: 'brand.primary' } : {}}
transition="border-color 0.5s"
{...rest}
>
{children}
</Stack>
)
}
export const CardLayout = forwardRef<HTMLDivElement, CardLayoutProps>(
({ children, noborder, click, hover, ...rest }, ref) => {
return (
<Stack
ref={ref}
as={rest.to ? Link : undefined}
tabIndex={-1}
overflow={'hidden'}
backgroundColor="white"
border="2px solid"
borderColor={noborder ? 'transparent' : 'brand.neutral200'}
borderRadius="8px"
boxShadow="none"
padding="24px"
spacing="10px"
_hover={
hover ? { cursor: 'pointer', borderColor: 'brand.neutral400' } : {}
}
_active={click ? { borderColor: 'brand.primary' } : {}}
_focus={click ? { borderColor: 'brand.primary' } : {}}
transition="border-color 0.5s"
{...rest}
>
{children}
</Stack>
)
},
)
15 changes: 9 additions & 6 deletions src/components/nav/bottomNav/ProjectNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ProjectNav = ({ fixed }: { fixed?: boolean }) => {
setNoTransition(false)
onClose()
}
}, [isScrollingUp, mobileView, fixed])
}, [isScrollingUp, mobileView, fixed, onOpen, onClose])

return (
<>
Expand Down Expand Up @@ -78,10 +78,13 @@ export const ProjectNavUI = () => {
return 'brand.neutral600'
}

const transactionCount = project?.fundingTxsCount
const fundersCount = project?.fundersCount
if (!project) {
return null
}

const { fundersCount, fundingTxsCount } = project

const isOwner = project?.owners[0]?.user?.id === user.id
const isOwner = project.owners[0]?.user?.id === user.id

const handleClick = (value: MobileViews) => {
if (mobileView === value) {
Expand Down Expand Up @@ -129,8 +132,8 @@ export const ProjectNavUI = () => {
_hover={{}}
paddingX="5px"
>
{transactionCount && (
<Text fontFamily={fonts.mono}>{transactionCount}</Text>
{fundingTxsCount && (
<Text fontFamily={fonts.mono}>{fundingTxsCount}</Text>
)}
</Button>
<Button
Expand Down
4 changes: 2 additions & 2 deletions src/config/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { NotFoundPage } from '../pages/notFound'
import { Profile } from '../pages/profile'
import {
ProjectContributors,
ProjectDashboard,
ProjectDashboardPage,
ProjectDescription,
ProjectDetails,
ProjectFundingSettings,
Expand Down Expand Up @@ -118,7 +118,7 @@ const platformRoutes = [
},
{
path: getPath('projectDashboard', PathName.projectId),
element: ProjectDashboard,
element: ProjectDashboardPage,
authenticated: true,
nested: [
{
Expand Down
8 changes: 5 additions & 3 deletions src/config/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export const theme = extendTheme({
},
transparent: {
backgroundColor: 'transparent',
border: '1px solid',
color: colors.neutral600,
border: 'none',
borderColor: 'transparent',
_hover: {
borderColor: colors.neutral900,
backgroundColor: colors.neutral200,
},
_active: {
backgroundColor: colors.neutral900,
backgroundColor: colors.neutral300,
color: colors.textBlack,
},
},
containedClear: {
Expand Down
5 changes: 0 additions & 5 deletions src/constants/components/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export const ID = {
contribution: 'project-activity-list-container',
leaderboard: 'project-leaderboard-list-container',
},
view: {
entries: 'project-main-entries-container',
rewards: 'project-main-rewards-container',
milestones: 'project-main-milestones-container',
},
},
profile: {
tabs: 'user-profile-tab-container',
Expand Down
10 changes: 7 additions & 3 deletions src/context/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Project, User } from '../types/generated/graphql'
const defaultContext: AuthContextProps = {
isLoggedIn: false,
user: defaultUser,
isAnonymous: true,
loading: false,
error: undefined,
login() {},
Expand All @@ -30,7 +31,7 @@ const defaultContext: AuthContextProps = {
async getAuthToken() {
return false
},
setUser(user: User) {},
setUser() {},
followedProjects: [],
}

Expand All @@ -44,6 +45,7 @@ export type NavContextProps = {
type AuthContextProps = {
isLoggedIn: boolean
user: User
isAnonymous: boolean
loading: boolean
error?: ApolloError
login: (me: User) => void
Expand All @@ -55,7 +57,7 @@ type AuthContextProps = {
setIsLoggedIn: Dispatch<SetStateAction<boolean>>
queryCurrentUser: () => void
getAuthToken: () => Promise<boolean>
setUser: (user: User) => void
setUser: Dispatch<SetStateAction<User>>
followedProjects: Project[]
}

Expand Down Expand Up @@ -142,6 +144,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
}

setInitialLoad(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(() => {
Expand All @@ -156,12 +159,13 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
if (initialLoad) {
setLoading(loadingUser)
}
}, [loadingUser])
}, [initialLoad, loadingUser])

return (
<AuthContext.Provider
value={{
user,
isAnonymous: !(user && user.id),
queryCurrentUser,
setUser,
loading,
Expand Down
63 changes: 49 additions & 14 deletions src/context/project.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createContext, useContext, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'

import { getPath } from '../constants'
import { useProjectState } from '../hooks/graphqlState'
import { ProjectFragment } from '../types'
import { useAuthContext } from './auth'
import { useNavContext } from './nav'

export enum MobileViews {
description = 'description',
Expand All @@ -11,30 +15,29 @@ export enum MobileViews {
}

type ProjectState = {
project: ProjectFragment
updateProject?: (updateProject: Partial<ProjectFragment>) => void
saveProject?: () => Promise<void>
saving?: boolean
projectId?: string | number
}

type ProjectContextProps = {
project: ProjectFragment
project: ProjectFragment | null
updateProject: (updateProject: Partial<ProjectFragment>) => void
saveProject: () => Promise<void>
mobileView: MobileViews
setMobileView: (view: MobileViews) => void
isProjectOwner: boolean
saving?: boolean
loading?: boolean
error: any
}

const defaultProjectContext = {
mobileView: MobileViews.description,
setMobileView(_view: MobileViews) {},
project: {} as ProjectFragment,
project: null,
updateProject() {},
async saveProject() {},
isProjectOwner: false,
saving: false,
loading: false,
error: null,
}

export const ProjectContext = createContext<ProjectContextProps>(
Expand All @@ -44,25 +47,56 @@ export const ProjectContext = createContext<ProjectContextProps>(
export const useProjectContext = () => useContext(ProjectContext)

export const ProjectProvider = ({
project,
updateProject = defaultProjectContext.updateProject,
saveProject = defaultProjectContext.saveProject,
saving,
projectId,
children,
}: { children: React.ReactNode } & ProjectState) => {
const navigate = useNavigate()
const { setNavData } = useNavContext()
const [mobileView, setMobileView] = useState<MobileViews>(
MobileViews.description,
)
const [isProjectOwner, setIsProjectOwner] = useState(false)
const { user } = useAuthContext()

const { error, loading, project, updateProject, saveProject } =
useProjectState(projectId || '', {
skip: !projectId,

onError() {
navigate(getPath('notFound'))
},

onCompleted(data) {
if (!data?.project) {
navigate(getPath('notFound'))
return
}

const { project } = data

setNavData({
projectName: project.name,
projectTitle: project.title,
projectPath: getPath('project', project.name),
projectOwnerIDs:
project.owners.map((ownerInfo) => {
return Number(ownerInfo.user.id || -1)
}) || [],
})
},
})

useEffect(() => {
if (!project) {
return
}

if (project.id && project.owners[0]?.user.id === user.id) {
setIsProjectOwner(true)
} else {
setIsProjectOwner(false)
}
}, [project.id, project.owners, user])
}, [project, user])

return (
<ProjectContext.Provider
Expand All @@ -73,7 +107,8 @@ export const ProjectProvider = ({
isProjectOwner,
updateProject,
saveProject,
saving,
error,
loading,
}}
>
{children}
Expand Down
Loading