Skip to content

Commit

Permalink
Merge pull request stakwork#976 from jordan-ae/text-snippets
Browse files Browse the repository at this point in the history
Create a Reusable UI Component on "Add Bounty Modal" that allows you to add a snippet to the description
humansinstitute authored Jan 28, 2025
2 parents c879f6f + 0538360 commit 922fe8f
Showing 4 changed files with 41 additions and 3 deletions.
35 changes: 33 additions & 2 deletions src/components/form/bounty/index.tsx
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 6 additions & 0 deletions src/components/form/schema.ts
Original file line number Diff line number Diff line change
@@ -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 ',
2 changes: 1 addition & 1 deletion src/people/utils/BountyCreationConstant.ts
Original file line number Diff line number Diff line change
@@ -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: {
1 change: 1 addition & 0 deletions src/store/interface.ts
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 922fe8f

Please sign in to comment.