Skip to content

Commit

Permalink
support selecting cv template
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Jan 1, 2024
1 parent fa3b79c commit 66d1709
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/components/generator/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormProvider, useForm } from 'react-hook-form'
import { useAtom } from 'jotai'
import styled from 'styled-components'

import { TemplatesSection } from './sections/TemplatesSection'
import { ProfileSection } from './sections/ProfileSection'
import { EducationSection } from './sections/EducationSection'
import { WorkSection } from './sections/WorkSection'
Expand Down Expand Up @@ -34,7 +35,7 @@ const initialFormValues: FormValues = {

export function Form() {
const router = useRouter()
const { section: currSection } = router.query
const { section: currSection = 'basics' } = router.query

const [resume, setResume] = useAtom(resumeAtom)
const formContext = useForm<FormValues>({ defaultValues: initialFormValues })
Expand Down Expand Up @@ -70,9 +71,8 @@ export function Form() {
<StyledForm
id="resume-form"
onSubmit={formContext.handleSubmit(handleFormSubmit)}
// onChange={handleFormSubmit}
>
{!currSection && <ProfileSection />}
{currSection === 'templates' && <TemplatesSection />}
{currSection === 'basics' && <ProfileSection />}
{currSection === 'education' && <EducationSection />}
{currSection === 'work' && <WorkSection />}
Expand Down
32 changes: 32 additions & 0 deletions src/components/generator/form/sections/TemplatesSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useFormContext, Controller } from 'react-hook-form'

import { FormSection } from './FormSection'
import { TEMPLATES } from '../../../../lib/templates/constants'

import { FormValues } from '../../../../types'

export function TemplatesSection() {
const { control } = useFormContext<FormValues>()

return (
<FormSection title="Choose a Template">
{TEMPLATES.map((templateId) => (
<label key={templateId} style={{ display: 'inline-block', padding: 8 }}>
Template {templateId}
<Controller
control={control}
name="selectedTemplate"
render={({ field }) => (
<input
type="radio"
onChange={(e) => field.onChange(Number(e.target.value))}
value={templateId}
checked={field.value === templateId}
/>
)}
/>
</label>
))}
</FormSection>
)
}
14 changes: 0 additions & 14 deletions src/components/generator/templates/Templates.tsx

This file was deleted.

12 changes: 12 additions & 0 deletions src/lib/templates/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@ export const TEMPLATE8 = 8
export const TEMPLATE9 = 9
export const TEMPLATE10 = 10

export const TEMPLATES = [
TEMPLATE1,
TEMPLATE2,
TEMPLATE3,
TEMPLATE4,
TEMPLATE5,
TEMPLATE6,
TEMPLATE7,
TEMPLATE8,
TEMPLATE9
]

export const NEWLINE = '\\\\'
export const WHITESPACE = '\\ '

0 comments on commit 66d1709

Please sign in to comment.