Skip to content

Commit

Permalink
feat: Add Temporary WIP UpdateResumeScreen & formState
Browse files Browse the repository at this point in the history
  • Loading branch information
codinsonn committed Dec 6, 2023
1 parent 71ba3f2 commit 4aba3ae
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 5 deletions.
2 changes: 2 additions & 0 deletions apps/expo/app/(generated)/cv/[slug]/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// -i- Automatically generated by 'yarn link-routes', do not modify manually
export { default } from 'cv-page/routes/cv/[slug]/edit/index'
2 changes: 2 additions & 0 deletions apps/next/app/(generated)/cv/[slug]/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use client'
export { default, dynamic } from 'cv-page/routes/cv/[slug]/edit/index'
16 changes: 16 additions & 0 deletions features/cv-page/forms/useResumeDataForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useFormState } from 'aetherspace/forms/useFormState'
import { ResumeData } from 'cv-page/schemas/ResumeData'

/* --- useResumeDataForm() --------------------------------------------------------------------- */

const useResumeDataForm = (initialValues) => {
const formState = useFormState({
stateSchema: ResumeData,
initialValues,
})
return formState
}

/* --- Exports --------------------------------------------------------------------------------- */

export default useResumeDataForm
5 changes: 0 additions & 5 deletions features/cv-page/resolvers/upsertResume.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { aetherResolver } from 'aetherspace/utils/serverUtils'
// Types
import { TMongoUpdateResult } from '@aetherspace/mongoose/schemas'
// Schemas
import { UpsertResumeAPIConfig } from '../schemas/UpsertResumeResolver'
// Models
import { ResumeDataModel } from '../schemas/models'
// Mocks
import { dummyResumeData } from '../mocks/resumeData.mock'
// Utils
import { dbConnect } from '@aetherspace/mongoose/utils'

/* --- Constants ------------------------------------------------------------------------------- */
Expand Down
22 changes: 22 additions & 0 deletions features/cv-page/routes/cv/[slug]/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
// Navigation
import { AetherPage } from 'aetherspace/navigation'
// Screens
import * as UpdateResumeScreen from '../../../../screens/UpdateResumeScreen'

/* --- Config ---------------------------------------------------------------------------------- */

const ScreenComponent = UpdateResumeScreen.UpdateResumeScreen
const screenConfig = UpdateResumeScreen.screenConfig

/* --- /cv/[slug]/edit ------------------------------------------------------------------------- */

const PageScreen = (props: UpdateResumeScreen.TUpdateResumeScreenProps) => (
<AetherPage {...props} screen={ScreenComponent} screenConfig={screenConfig} />
)

/* --- Exports --------------------------------------------------------------------------------- */

export const dynamic = screenConfig.dynamic

export default PageScreen
75 changes: 75 additions & 0 deletions features/cv-page/screens/UpdateResumeScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react'
import { useAetherRoute } from 'aetherspace/navigation'
import { z, AetherProps, createDataBridge } from 'aetherspace/schemas'
import { GetResumeDataByUserSlugDataBridge } from '..//schemas/GetResumeDataByUserSlugDataBridge.ts'
import { View } from 'aetherspace/primitives'
import { H1, P } from 'aetherspace/html-elements'
import useResumeDataForm from '../forms/useResumeDataForm.ts'
import { dummyResumeData } from '../mocks/resumeData.mock.ts'

/* --- Schemas & Types ------------------------------------------------------------------------- */

const UpdateResumeScreenParams = GetResumeDataByUserSlugDataBridge.argsSchema
const UpdateResumeScreenResponse = GetResumeDataByUserSlugDataBridge.responseSchema

const UpdateResumeScreenProps = UpdateResumeScreenResponse.extendSchema('UpdateResumeScreenProps', {
params: UpdateResumeScreenParams.optional(),
segment: z.string().optional(),
}).example({
params: { slug: 'codinsonn' },
...dummyResumeData,
})

export type TUpdateResumeScreenProps = AetherProps<typeof UpdateResumeScreenProps>

/* --- Data Fetching Bridge -------------------------------------------------------------------- */

export const screenConfig = createDataBridge({
...GetResumeDataByUserSlugDataBridge,
paramsSchema: UpdateResumeScreenParams,
propsSchema: UpdateResumeScreenProps,
dynamic: 'auto', // -i- https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
})

/* --- <UpdateResumeScreen/> ------------------------------------------------------------------- */

export const UpdateResumeScreen = (props: TUpdateResumeScreenProps) => {
// Data
const [screenData, { error }] = useAetherRoute(props, screenConfig)

// Forms
const formState = useResumeDataForm(screenData)

// -- Effects --

React.useEffect(() => {
formState.handleChange('slug', 'codinsonnn')
}, [])

Check warning on line 47 in features/cv-page/screens/UpdateResumeScreen.tsx

View workflow job for this annotation

GitHub Actions / check-linting

React Hook React.useEffect has a missing dependency: 'formState'. Either include it or remove the dependency array

// -- Guards --

if (error) {
return (
<View tw="w-full h-full items-center justify-center">
<H1 tw="text-red-500">Error: {error.message}</H1>
</View>
)
}

// -- Render --

return (
<View tw="w-full h-full items-center justify-center">
<H1 tw="text-xl text-black">UpdateResumeScreen</H1>
<P>{JSON.stringify(formState.values, null, 4)}</P>
</View>
)
}

/* --- Documentation --------------------------------------------------------------------------- */

// export const getDocumentationProps = UpdateResumeScreenProps.introspect()

/* --- Exports --------------------------------------------------------------------------------- */

export default UpdateResumeScreen
2 changes: 2 additions & 0 deletions features/cv-page/screens/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { ResumeScreen, TResumeScreenProps } from './ResumeScreen'
export { UpdateResumeScreen, TUpdateResumeScreenProps } from './UpdateResumeScreen'

Check warning on line 3 in features/cv-page/screens/index.ts

View workflow job for this annotation

GitHub Actions / check-linting

Delete `⏎`
1 change: 1 addition & 0 deletions packages/@registries/routeManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const routeManifest = {
['/']: 'BioScreen',
['/links']: 'BioScreen',
['/resume']: 'ResumeScreen',
['/cv/[slug]/edit']: 'UpdateResumeScreen',
['/cv/[slug]']: 'ResumeScreen',
['/resume/[slug]']: 'ResumeScreen',
} as const
Expand Down

0 comments on commit 4aba3ae

Please sign in to comment.