Move create project into plus button (#531)
The draft page used to automatically create a new project and route the user to the new project if the user was signed in. Problem arose if the user use the back button as they would end up creating more project. resolved my moving this logic into the plus button itself Resolves #511
This commit was merged in pull request #531.
This commit is contained in:
@@ -1,35 +1,6 @@
|
||||
import { useMutation } from '@redwoodjs/web'
|
||||
import { toast } from '@redwoodjs/web/toast'
|
||||
import { useEffect } from 'react'
|
||||
import { useAuth } from '@redwoodjs/auth'
|
||||
import { navigate, routes } from '@redwoodjs/router'
|
||||
|
||||
import DevIdePage from 'src/pages/DevIdePage/DevIdePage'
|
||||
import useUser from 'src/helpers/hooks/useUser'
|
||||
import { CREATE_PROJECT_MUTATION } from 'src/components/ProjectCell/ProjectCell'
|
||||
|
||||
const DraftProjectPage = ({ cadPackage }: { cadPackage: string }) => {
|
||||
const { isAuthenticated } = useAuth()
|
||||
const { user, loading } = useUser()
|
||||
const [createProject] = useMutation(CREATE_PROJECT_MUTATION, {
|
||||
onCompleted: ({ createProject }) => {
|
||||
navigate(
|
||||
routes.ide({
|
||||
userName: createProject?.user?.userName,
|
||||
projectTitle: createProject?.title,
|
||||
})
|
||||
)
|
||||
toast.success('Project Created.')
|
||||
},
|
||||
})
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && user) {
|
||||
createProject({ variables: { input: { userId: user.id, cadPackage } } })
|
||||
}
|
||||
}, [isAuthenticated, user])
|
||||
if (loading || user?.id) {
|
||||
return <div>loading</div>
|
||||
}
|
||||
return <DevIdePage cadPackage={cadPackage} />
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user