diff --git a/src/components/form/bounty/index.tsx b/src/components/form/bounty/index.tsx index 9ddf26ef..2c35260b 100644 --- a/src/components/form/bounty/index.tsx +++ b/src/components/form/bounty/index.tsx @@ -1,9 +1,11 @@ +/* eslint-disable react/prop-types */ import { EuiText } from '@elastic/eui'; import { Formik } from 'formik'; import { observer } from 'mobx-react-lite'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { useIsMobile } from 'hooks'; import { RefineDescriptionModal } from 'components/common/RefineDescriptionModal'; +import { snippetStore } from 'store/snippetStore'; import { toCapitalize } from '../../../helpers/helpers'; import api from '../../../api'; import { colors } from '../../../config/colors'; @@ -111,6 +113,10 @@ function Form(props: FormProps) { fetchWorkspaces(); }, [main, ui.meInfo?.id]); + useEffect(() => { + snippetStore.loadSnippets(workspaceid); + }, [workspaceid]); + useEffect(() => { (async () => { try { @@ -201,8 +207,6 @@ function Form(props: FormProps) { status: 'active' }); - console.log(features); - if (Array.isArray(features)) { allFeatures = [...allFeatures, ...features]; console.log(allFeatures); @@ -230,6 +234,14 @@ function Form(props: FormProps) { })(); }, [main, workspaceid]); + const snippets = snippetStore.getAllSnippets(); + + const filteredSnippets = snippets.map((p: any) => ({ + value: p.id, + label: p.title, + snippet: p.snippet + })); + useEffect(() => { (async () => { try { @@ -293,6 +305,10 @@ function Form(props: FormProps) { if (phaseFieldIndex !== -1) { schema[phaseFieldIndex].options = featurePhase; } + const snippetFieldIndex = schema.findIndex((field: FormField) => field.name === 'text_snippet'); + if (snippetFieldIndex !== -1) { + schema[snippetFieldIndex].options = filteredSnippets; + } } schema = isMobile ? swapElements([...schema], 7, 8) : schema; @@ -610,6 +626,21 @@ function Form(props: FormProps) { }} handleChange={(e: any) => { setFieldValue(item.name, e); + + if (item.name === 'text_snippet') { + const selectedSnippet = filteredSnippets.find( + (snippet: { + value: string; + label: string; + snippet: string; + }) => snippet.value === e + ); + if (selectedSnippet) { + const existingDescription = values.description || ''; + const descriptionContent = `${existingDescription}\n\n${selectedSnippet.snippet}`; + setFieldValue('description', descriptionContent.trim()); + } + } }} setFieldValue={(e: any, f: any) => { setFieldValue(e, f); diff --git a/src/components/form/schema.ts b/src/components/form/schema.ts index 13c6f7a4..3ddce3fc 100644 --- a/src/components/form/schema.ts +++ b/src/components/form/schema.ts @@ -719,6 +719,12 @@ export const wantedCodingTaskSchema: FormField[] = [ type: 'creatablemultiselect', options: codingLanguages }, + { + name: 'text_snippet', + label: 'Text Snippet Title', + type: 'select', + options: [] + }, { name: 'github_description', label: 'Get Description From Github ', diff --git a/src/people/utils/BountyCreationConstant.ts b/src/people/utils/BountyCreationConstant.ts index b734cbea..25853f10 100644 --- a/src/people/utils/BountyCreationConstant.ts +++ b/src/people/utils/BountyCreationConstant.ts @@ -38,7 +38,7 @@ export const BountyDetailsCreationData = { schemaName: 'Freelance Job Request', heading: 'Description', sub_heading: ' ', - schema: ['github_description', 'description', 'issue_template'], + schema: ['text_snippet', 'github_description', 'description', 'issue_template'], schema2: [' ', 'loomEmbedUrl'], required: [''], outerContainerStyle: { diff --git a/src/store/interface.ts b/src/store/interface.ts index 15a64a51..4bcdc365 100644 --- a/src/store/interface.ts +++ b/src/store/interface.ts @@ -119,6 +119,7 @@ export interface PersonBounty { commitment_fee?: number; feature_id?: string; phase_id?: string; + text_snippet_id?: string; } export type WorkspaceTransactionType = 'deposit' | 'payment' | 'withdraw' | 'failed' | 'pending';