Skip to content

Commit

Permalink
Merge pull request stakwork#863 from jordan-ae/add-feature-phase
Browse files Browse the repository at this point in the history
  • Loading branch information
humansinstitute authored Jan 5, 2025
2 parents 47cf11e + 1fafc1b commit d0146c6
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
67 changes: 67 additions & 0 deletions src/components/form/bounty/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ function Form(props: FormProps) {
const { main, ui } = useStores();
const color = colors['light'];
const [isFocused, setIsFocused] = useState({});
const [workspaceid, setWorskspaceid] = useState('');
const [featureid, setFeatureid] = useState('');
const [workspaceFeature, setWorkspaceFeatures] = useState<
Array<{ value: string; label: string }>
>([]);
const [featurePhase, setFeaturedPhase] = useState<Array<{ value: string; label: string }>>([]);

const [schemaData, setSchemaData] = useState(BountyDetailsCreationData.step_1);
const [stepTracker, setStepTracker] = useState<number>(1);
Expand Down Expand Up @@ -162,8 +168,64 @@ function Form(props: FormProps) {

let schema = props.paged ? props.schema?.filter((f: any) => f.page === page) : props.schema;

useEffect(() => {
(async () => {
try {
const features = await main.getWorkspaceFeatures(workspaceid, {
page: 1,
status: 'active'
});

if (Array.isArray(features)) {
const filteredFeatures = features.map(
({ uuid, name }: { uuid: string; name: string }) => ({
value: uuid,
label: name
})
);

setWorkspaceFeatures(filteredFeatures);
} else {
console.log('Features object:', features);
}
} catch (error) {
console.error('Error fetching or parsing features:', error);
}
})();
}, [main, featureid, workspaceFeature, workspaceid]);

useEffect(() => {
(async () => {
try {
const phase = await main.getFeaturePhases(featureid);

if (Array.isArray(phase)) {
const filteredPhase = phase.map(({ uuid, name }: { uuid: string; name: string }) => ({
value: uuid,
label: name
}));
setFeaturedPhase(filteredPhase);
} else {
console.log('Features object:', phase);
}
} catch (error) {
console.error('Error fetching or parsing features:', error);
}
})();
}, [featureid, main]);

// replace schema with dynamic schema if there is one
schema = dynamicSchema || schema;
if (schema && Array.isArray(schema)) {
const featureFieldIndex = schema.findIndex((field: FormField) => field.name === 'feature_id');
if (featureFieldIndex !== -1) {
schema[featureFieldIndex].options = workspaceFeature;
}
const phaseFieldIndex = schema.findIndex((field: FormField) => field.name === 'phase_id');
if (phaseFieldIndex !== -1) {
schema[phaseFieldIndex].options = featurePhase;
}
}

schema = isMobile ? swapElements([...schema], 7, 8) : schema;

Expand Down Expand Up @@ -214,6 +276,11 @@ function Form(props: FormProps) {
key === '' ? true : values?.[key]
);

if (values.org_uuid !== '') {
setFeatureid(values.feature_id);
setWorskspaceid(values.org_uuid);
}

const isBtnDisabled = (stepTracker === 3 && !isDescriptionValid) || !valid;

// returns the body of a form page
Expand Down
14 changes: 14 additions & 0 deletions src/components/form/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,20 @@ export const wantedCodingTaskSchema: FormField[] = [
type: 'text',
testId: 'Github'
},
{
name: 'feature_id',
label: 'Feature',
type: 'select',
options: [],
validator: strValidatorNotRequired
},
{
name: 'phase_id',
label: 'Phase',
type: 'select',
options: [],
validator: strValidatorNotRequired
},
{
name: 'wanted_type',
label: 'Category *',
Expand Down
2 changes: 2 additions & 0 deletions src/people/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export interface WantedSummaryProps {
formSubmit: (any, notEdit?: boolean) => void;
title: string;
org_uuid?: string;
phase_id?: string;
feature_id?: string;
id?: number;
owner_id?: string;
markPaidOrUnpaid?: ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion src/people/utils/BountyCreationConstant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const BountyDetailsCreationData = {
schemaName: 'Freelance Job Request',
heading: 'Basic info',
sub_heading: ' ',
schema: ['org_uuid', 'one_sentence_summary', 'ticket_url'],
schema: ['org_uuid', 'one_sentence_summary', 'ticket_url', 'phase_id', 'feature_id'],
schema2: ['wanted_type', 'coding_languages'],
required: ['one_sentence_summary', 'wanted_type'],
outerContainerStyle: {
Expand Down
20 changes: 16 additions & 4 deletions src/people/widgetViews/summaries/WantedSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function WantedSummary(props: WantedSummaryProps) {
formSubmit,
title,
org_uuid,
feature_id,
phase_id,
id,
isEditButtonDisable
} = props;
Expand Down Expand Up @@ -161,7 +163,9 @@ function WantedSummary(props: WantedSummaryProps) {
show: show,
type: type,
created: created,
org_uuid
org_uuid,
phase_id,
feature_id
};

formSubmit && formSubmit(newValue, true);
Expand All @@ -181,7 +185,9 @@ function WantedSummary(props: WantedSummaryProps) {
ticket_url,
titleString,
type,
wanted_type
wanted_type,
phase_id,
feature_id
]
);

Expand All @@ -204,7 +210,9 @@ function WantedSummary(props: WantedSummaryProps) {
show: show,
type: type,
created: created,
org_uuid
org_uuid,
phase_id,
feature_id
};
formSubmit && formSubmit(newValue, true);
}, [
Expand All @@ -222,7 +230,9 @@ function WantedSummary(props: WantedSummaryProps) {
ticket_url,
titleString,
type,
wanted_type
wanted_type,
phase_id,
feature_id
]);

useEffect(() => {
Expand Down Expand Up @@ -600,6 +610,8 @@ function WantedSummary(props: WantedSummaryProps) {
actionButtons={actionButtons}
assigneeLabel={assigneeLabel}
isEditButtonDisable={isEditButtonDisable}
phase_id={phase_id}
feature_id={feature_id}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ describe('MobileView component', () => {
badgeRecipient: '',
fromBountyPage: '',
wanted_type: '',
phase_id: '',
feature_id: '',
one_sentence_summary: '',
github_description: '',
show: false,
Expand Down
2 changes: 2 additions & 0 deletions src/store/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface PersonBounty {
estimated_session_length: string;
bounty_expires?: string;
commitment_fee?: number;
feature_id?: string;
phase_id?: string;
}

export type WorkspaceTransactionType = 'deposit' | 'payment' | 'withdraw' | 'failed' | 'pending';
Expand Down

0 comments on commit d0146c6

Please sign in to comment.