Skip to content

Commit

Permalink
including the richt text editor in the front end
Browse files Browse the repository at this point in the history
  • Loading branch information
niclasheun committed Jan 6, 2025
1 parent 60c0800 commit 0cafe5d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { UseFormReturn } from 'react-hook-form'
import { FormDescription, FormLabel } from '@/components/ui/form'
import { FormLabel } from '@/components/ui/form'
import { Checkbox } from '@/components/ui/checkbox'
import { ApplicationQuestionMultiSelect } from '@/interfaces/application_question_multi_select'
import { FormDescriptionHTML } from '../components/FormDescriptionHTML'

interface CheckboxQuestionProps {
form: UseFormReturn<{ answers: string[] }>
Expand All @@ -28,7 +29,7 @@ export const CheckboxQuestion: React.FC<CheckboxQuestionProps> = ({
{question.title}
{question.is_required && <span className='text-destructive'> *</span>}
</FormLabel>
{question.description && <FormDescription>{question.description}</FormDescription>}
{question.description && <FormDescriptionHTML htmlCode={question.description} />}
</div>
</div>
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { UseFormReturn } from 'react-hook-form'
import { FormDescription, FormLabel } from '@/components/ui/form'
import { FormLabel } from '@/components/ui/form'
import { MultiSelect } from '@/components/MultiSelect'
import { ApplicationQuestionMultiSelect } from '@/interfaces/application_question_multi_select'
import {
Expand All @@ -10,6 +10,7 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { FormDescriptionHTML } from '../components/FormDescriptionHTML'

interface MultiSelectQuestionProps {
form: UseFormReturn<{ answers: string[] }>
Expand All @@ -35,7 +36,7 @@ export const MultiSelectQuestion: React.FC<MultiSelectQuestionProps> = ({
{question.title}
{question.min_select > 0 && <span className='text-destructive'> *</span>}
</FormLabel>
{question.description && <FormDescription>{question.description}</FormDescription>}
{question.description && <FormDescriptionHTML htmlCode={question.description} />}
{question.max_select > 1 ? (
<MultiSelect
options={multiSelectOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { zodResolver } from '@hookform/resolvers/zod'
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
Expand All @@ -15,6 +14,7 @@ import { Textarea } from '@/components/ui/textarea'
import { QuestionTextFormRef } from '../utils/QuestionTextFormRef'
import { createValidationSchema } from './validationSchema'
import { ApplicationQuestionText } from '@/interfaces/application_question_text'
import { FormDescriptionHTML } from '../components/FormDescriptionHTML'

interface ApplicationQuestionTextFormProps {
question: ApplicationQuestionText
Expand Down Expand Up @@ -72,9 +72,7 @@ export const ApplicationQuestionTextForm = forwardRef(function ApplicationQuesti
{question.title}
{question.is_required ? <span className='text-destructive'> *</span> : ''}
</FormLabel>
{question.description && (
<FormDescription>{question.description}</FormDescription>
)}
{question.description && <FormDescriptionHTML htmlCode={question.description} />}
<div className='relative'>
{isTextArea ? (
<Textarea
Expand Down
25 changes: 25 additions & 0 deletions clients/core/src/Application/components/FormDescriptionHTML.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { FormDescription } from '@/components/ui/form'

interface FormDescriptionHTMLProps {
htmlCode: string
}

export const FormDescriptionHTML = ({ htmlCode }: FormDescriptionHTMLProps): JSX.Element => {
return (
<FormDescription>
<style>
{`
a {
cursor: pointer;
color: #1d4ed8; /* Equivalent to text-blue-700 */
text-decoration: underline; /* Always underlined */
}
a:hover {
text-decoration: underline; /* Ensure underline on hover */
}
`}
</style>
<div dangerouslySetInnerHTML={{ __html: htmlCode }} />
</FormDescription>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { DeleteConfirmation } from '../components/DeleteConfirmation'
import { questionsEqual } from '../handlers/computeQuestionsModified'
import { QuestionStatus, QuestionStatusBadge } from '../components/QuestionStatusBadge'
import { checkCheckBoxQuestion } from '../../../../Application/utils/CheckBoxRequirements'
import { DescriptionMinimalTiptapEditor } from '@/components/minimal-tiptap/form-description-tiptap'
import { TooltipProvider } from '@/components/ui/tooltip'

// If you plan to expose methods via this ref, define them here:
export interface ApplicationQuestionCardRef {
Expand Down Expand Up @@ -177,12 +179,26 @@ export const ApplicationQuestionCard = forwardRef<
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Input {...field} placeholder='Enter question description' />
<TooltipProvider>
<DescriptionMinimalTiptapEditor
{...field}
// value={richEditorValue}
// onChange={(answer) => setRichEditorValue(answer)}
className='w-full'
editorContentClassName='minimal-tiptap-editor'
output='html'
placeholder='Type your description here...'
autofocus={false}
editable={true}
editorClassName='focus:outline-none'
/>
</TooltipProvider>
</FormControl>
<FormMessage />
</FormItem>
)}
/>

{/** Checkbox Questions do not have a placeholder */}
{!isCheckboxQuestion && (
<FormField
Expand Down

0 comments on commit 0cafe5d

Please sign in to comment.