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

closed #2391

Closed
Closed

closed #2391

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
29 changes: 24 additions & 5 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { useDataStore } from '~/stores/useDataStore'
import { useFeatureFlagStore } from '~/stores/useFeatureFlagStore'
import { useUpdateSelectedNode } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { useTeachStore } from '~/stores/useTeachStore'
import { useUserStore } from '~/stores/useUserStore'
import {
Expand Down Expand Up @@ -53,12 +54,17 @@
const LazyUniverse = lazy(() => import('~/components/Universe').then(({ Universe }) => ({ default: Universe })))
const LazySideBar = lazy(() => import('./SideBar').then(({ SideBar }) => ({ default: SideBar })))

const LazyOnboardingModal = lazy(() =>
import('../ModalsContainer/OnboardingFlow').then(({ OnboardingModal }) => ({ default: OnboardingModal })),
)

export const App = () => {
const [searchParams] = useSearchParams()
const query = searchParams.get('q')
const { setBudget, setNodeCount } = useUserStore((s) => s)
const { setBudget, setNodeCount, isAdmin } = useUserStore((s) => s)
const queueRef = useRef<FetchDataResponse | null>(null)
const timerRef = useRef<NodeJS.Timeout | null>(null)
const { open, visible } = useModal('onboardingFlow')

const {
setSidebarOpen,
Expand All @@ -68,6 +74,7 @@
setTranscriptOpen,
universeQuestionIsOpen,
setUniverseQuestionIsOpen,
appMetaData,
} = useAppStore((s) => s)

const setTeachMeAnswer = useTeachStore((s) => s.setTeachMeAnswer)
Expand Down Expand Up @@ -295,7 +302,7 @@
}

ws.onmessage = (event) => {
console.log('Message from server:', event.data)

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 305 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

const data = JSON.parse(event.data)

Expand All @@ -317,15 +324,21 @@
}

ws.onclose = () => {
console.log('WebSocket connection closed')

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 327 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement
}
}, [runningProjectId, setRunningProjectMessages])

useEffect(() => {
if (!splashDataLoading) {
if (isAdmin && !appMetaData?.title && !visible) {
open()
}
}, [isAdmin, appMetaData?.title, open, visible])

useEffect(() => {
if (!splashDataLoading && !visible) {
setUniverseQuestionIsOpen()
}
}, [setUniverseQuestionIsOpen, splashDataLoading])
}, [setUniverseQuestionIsOpen, splashDataLoading, visible])

return (
<>
Expand All @@ -336,7 +349,13 @@
<Leva hidden={!isDevelopment || true} isRoot />

<Suspense fallback={<div>Loading...</div>}>
{!splashDataLoading ? (
{visible && (
<Suspense fallback={<div>Loading Onboarding...</div>}>
<LazyOnboardingModal onSuccess={setUniverseQuestionIsOpen} />
</Suspense>
)}

{!visible && !splashDataLoading && (
<Wrapper direction="row">
<FormProvider {...form}>
<LazyMainToolbar />
Expand All @@ -351,7 +370,7 @@
<ModalsContainer />
<Toasts />
</Wrapper>
) : null}
)}
</Suspense>
</>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { Button } from '@mui/material'
import { FC, useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { MdError } from 'react-icons/md'
import styled from 'styled-components'
import { noSpacePattern } from '~/components/AddItemModal/SourceTypeStep/constants'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { TextInput } from '~/components/common/TextInput'
import { requiredRule } from '~/constants'
import { colors } from '~/utils'

type Props = {
onSubmit: () => void
error?: string
}

export const GraphDetailsStep: FC<Props> = ({ onSubmit, error }) => {
const {
formState: { isSubmitting },
watch,
} = useFormContext()

const title = watch('title')
const description = watch('description')

const isFormValid = !!title?.trim() && !!description?.trim()

useEffect(() => {
const titleInput = document.getElementById('graph-title') as HTMLInputElement

if (titleInput) {
titleInput.focus()
}
}, [])

return (
<Flex>
{/* <Flex align="center" direction="column" justify="center">
<StyledText>Welcome to SecondBrain</StyledText>
<StyledSubText>Set a name and short description for your graph.</StyledSubText>
</Flex> */}

<Flex direction="column" justify="space-between">
<StyledText>Welcome to SecondBrain</StyledText>
<StyledSubText>Set a name and short description for your graph.</StyledSubText>
</Flex>

<StyledWrapper>
<Flex className="input__wrapper">
<TextInput
id="graph-title"
label="Title"
maxLength={50}
name="title"
placeholder="Type graph title here..."
rules={{
...requiredRule,
pattern: {
message: 'No leading whitespace allowed',
value: noSpacePattern,
},
}}
/>
<TextInput
id="graph-description"
label="Description"
maxLength={100}
name="description"
placeholder="Type graph description here..."
rules={{
...requiredRule,
pattern: {
message: 'No leading whitespace allowed',
value: noSpacePattern,
},
}}
/>
</Flex>
</StyledWrapper>

<Flex mt={10}>
<Button
color="secondary"
disabled={isSubmitting || !!error || !isFormValid}
onClick={onSubmit}
size="large"
variant="contained"
>
Confirm
</Button>
</Flex>
{error ? (
<StyledError>
<StyledErrorText>
<MdError className="errorIcon" />
<span>{error}</span>
</StyledErrorText>
</StyledError>
) : null}
</Flex>
)
}

const StyledText = styled(Text)`
font-size: 22px;
font-weight: 600;
font-family: 'Barlow';
margin-bottom: 10px;
`

const StyledSubText = styled(Text)`
font-size: 14px;
font-family: 'Barlow';
margin-bottom: 20px;
`

const StyledWrapper = styled(Flex)`
width: 100%;
display: flex;
justify-content: center;
gap: 10px;
margin: 0 0 15px 0;

.input__wrapper {
display: flex;
gap: 23px;
max-height: 225px;
overflow-y: auto;
padding-right: 20px;
width: calc(100% + 20px);
}
`

const StyledErrorText = styled(Flex)`
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 2px;

.errorIcon {
display: block;
font-size: 13px;
min-height: 13px;
min-width: 13px;
}

span {
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;
white-space: normal;
letter-spacing: 0.2px;
padding-left: 4px;
font-size: 13px;
font-family: Barlow;
line-height: 18px;
}
`

const StyledError = styled(Flex)`
display: flex;
align-items: center;
color: ${colors.primaryRed};
position: relative;
margin-top: 20px;
`
80 changes: 80 additions & 0 deletions src/components/ModalsContainer/OnboardingFlow/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useEffect, useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { SuccessNotify } from '~/components/common/SuccessToast'
import { BaseModal } from '~/components/Modal'
import { NODE_ADD_ERROR } from '~/constants'
import { postAboutData, TAboutParams } from '~/network/fetchSourcesData'
import { useModal } from '~/stores/useModalStore'
import { GraphDetailsStep } from './GraphDetailsStep'

export type FormData = {
title: string
description: string
}

type OnboardingModalProps = {
onSuccess: () => void
}

export const OnboardingModal = ({ onSuccess }: OnboardingModalProps) => {
const { close, visible } = useModal('onboardingFlow')
const form = useForm<FormData>({ mode: 'onChange' })
const { reset } = form
const [error, setError] = useState<string>('')

useEffect(() => {
if (!visible) {
reset()
setError('')
}
}, [visible, reset])

const submitGraphDetails = async (
data: TAboutParams,
successCallback: () => void,
onError: (error: string) => void,
) => {
try {
const res = (await postAboutData(data)) as Awaited<{ status: string }>

if (res.status === 'success') {
SuccessNotify('Graph details saved')
successCallback()
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
let errorMessage = NODE_ADD_ERROR

if (err?.status === 400) {
const errorRes = await err.json()

errorMessage = errorRes.errorCode || errorRes?.status || NODE_ADD_ERROR
} else if (err instanceof Error) {
errorMessage = err.message
}

onError(String(errorMessage))
}
}

const onSubmit = form.handleSubmit(async (data) => {
await submitGraphDetails(
data,
() => {
close()
onSuccess()
},
setError,
)
})

return (
<BaseModal id="onboardingFlow" kind="small" onClose={close} preventOutsideClose>
<FormProvider {...form}>
<form id="onboardingFlow-form" onSubmit={onSubmit}>
<GraphDetailsStep error={error} onSubmit={onSubmit} />
</form>
</FormProvider>
</BaseModal>
)
}
40 changes: 25 additions & 15 deletions src/components/ModalsContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { lazy } from 'react'
import { useAppStore } from '~/stores/useAppStore'

const LazySettingsModal = lazy(() =>
import('../SettingsModal').then(({ SettingsModal }) => ({ default: SettingsModal })),
Expand Down Expand Up @@ -46,19 +47,28 @@ const LazyCreateBountyModal = lazy(() =>
import('./CreateBountyModal').then(({ CreateBountyModal }) => ({ default: CreateBountyModal })),
)

export const ModalsContainer = () => (
<>
<LazyAddItemModal />
<LazyAddContentModal />
<LazySettingsModal />
<LazyEditNodeNameModal />
<LazyRemoveNodeModal />
<LazySourcesTableModal />
<LazyAddNodeEdgeModal />
<LazyChangeNodeTypeModal />
<LazyBlueprintModal />
<LazyMergeNodeModal />
<LazyUserFeedBackModal />
<LazyCreateBountyModal />
</>
const LazyOnboardingModal = lazy(() =>
import('./OnboardingFlow').then(({ OnboardingModal }) => ({ default: OnboardingModal })),
)

export const ModalsContainer = () => {
const { setUniverseQuestionIsOpen } = useAppStore((s) => s)

return (
<>
<LazyAddItemModal />
<LazyAddContentModal />
<LazySettingsModal />
<LazyEditNodeNameModal />
<LazyRemoveNodeModal />
<LazySourcesTableModal />
<LazyAddNodeEdgeModal />
<LazyChangeNodeTypeModal />
<LazyBlueprintModal />
<LazyMergeNodeModal />
<LazyUserFeedBackModal />
<LazyCreateBountyModal />
<LazyOnboardingModal onSuccess={setUniverseQuestionIsOpen} />
</>
)
}
2 changes: 2 additions & 0 deletions src/stores/useModalStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type AvailableModals =
| 'changeNodeType'
| 'feedback'
| 'createBounty'
| 'onboardingFlow'

type ModalStore = {
currentModals: Record<AvailableModals, boolean>
Expand Down Expand Up @@ -51,6 +52,7 @@ const defaultData = {
changeNodeType: false,
feedback: false,
createBounty: false,
onboardingFlow: false,
},
}

Expand Down
Loading