Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import {
useCallback,
useEffect,
useMemo,
useState,
} from 'react'
import type { FC } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
import type { NavigateFunction } from 'react-router-dom'
import { Controller, useForm } from 'react-hook-form'
import type {
ControllerRenderProps,
UseFormReturn,
} from 'react-hook-form'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { NavigateFunction, useNavigate, useParams } from 'react-router-dom'
import { Controller, ControllerRenderProps, useForm, UseFormReturn } from 'react-hook-form'
import _ from 'lodash'
import classNames from 'classnames'

Expand All @@ -25,13 +15,14 @@ import {
LinkButton,
} from '~/libs/ui'

import { FormAddWrapper } from '../common/FormAddWrapper'
import { FormAddDefaultReviewer } from '../../models'
import { formAddDefaultReviewerSchema } from '../../utils'
import {
useManageAddDefaultReviewer,
useManageAddDefaultReviewerProps,
} from '../../hooks'
import { FormAddWrapper } from '../common/FormAddWrapper'
import { FormAddDefaultReviewer } from '../../models'
import { formAddDefaultReviewerSchema } from '../../utils'
import { getAiWorkflows } from '../../services/ai-workflows.service'

import styles from './DefaultReviewersAddForm.module.scss'

Expand Down Expand Up @@ -127,6 +118,7 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => {
formState: { errors, isDirty },
}: UseFormReturn<FormAddDefaultReviewer> = useForm({
defaultValues: {
aiWorkflowId: '',
baseCoefficient: 0,
fixedAmount: 0,
incrementalCoefficient: 0,
Expand Down Expand Up @@ -165,11 +157,22 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => {
[doAddDefaultReviewer, doUpdateDefaultReviewer, isEdit, navigate],
)

const [aiWorkflows, setAiWorkflows] = useState<{ label: string; value: string }[]>([])

useEffect(() => {
getAiWorkflows()
.then((workflows: { id: string; name: string }[]) => {
const options = workflows.map((wf: { id: string; name: string }) => ({ label: wf.name, value: wf.id }))
setAiWorkflows(options)
})
}, [])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Consider adding error handling for the getAiWorkflows promise to manage potential failures, such as network issues or server errors. This will improve the robustness of the component.


const isMemberReview = watch('isMemberReview')

useEffect(() => {
if (defaultReviewerInfo) {
reset({
aiWorkflowId: defaultReviewerInfo.aiWorkflowId ?? '',
baseCoefficient: defaultReviewerInfo.baseCoefficient ?? 0,
fixedAmount: defaultReviewerInfo.fixedAmount ?? 0,
incrementalCoefficient: defaultReviewerInfo.incrementalCoefficient ?? 0,
Expand Down Expand Up @@ -460,17 +463,18 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => {
)
}}
/>

<div className={styles.inputField}>
<Controller
name='isAIReviewer'
name='shouldOpenOpportunity'
control={control}
render={function render(controlProps: {
field: ControllerRenderProps<FormAddDefaultReviewer, 'isAIReviewer'>
}) {
field: ControllerRenderProps<FormAddDefaultReviewer, 'shouldOpenOpportunity'>
}) {
return (
<InputCheckbox
name='isAIReviewer'
label='Is AI Reviewer'
name='shouldOpenOpportunity'
label='Should Open Opportunity'
onChange={function onChange(event: Event) {
const target = event.target as HTMLInputElement | null
controlProps.field.onChange(target?.checked ?? false)
Expand All @@ -482,28 +486,31 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => {
}}
/>
</div>
<div className={styles.inputField}>
{!isMemberReview && (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Ensure that the aiWorkflowId field is correctly reset when defaultReviewerInfo changes, especially if isMemberReview is toggled. This prevents stale data from being displayed or submitted.

<Controller
name='shouldOpenOpportunity'
name='aiWorkflowId'
control={control}
render={function render(controlProps: {
field: ControllerRenderProps<FormAddDefaultReviewer, 'shouldOpenOpportunity'>
field: ControllerRenderProps<FormAddDefaultReviewer, 'aiWorkflowId'>
}) {
return (
<InputCheckbox
name='shouldOpenOpportunity'
label='Should Open Opportunity'
onChange={function onChange(event: Event) {
const target = event.target as HTMLInputElement | null
controlProps.field.onChange(target?.checked ?? false)
}}
checked={controlProps.field.value}
<InputSelectReact
name='aiWorkflowId'
label='AI Workflow'
placeholder='Select AI Workflow'
options={aiWorkflows}
value={controlProps.field.value}
onChange={controlProps.field.onChange}
onBlur={controlProps.field.onBlur}
classNameWrapper={styles.inputField}
disabled={isLoading}
dirty
error={_.get(errors, 'aiWorkflowId.message')}
/>
)
}}
/>
</div>
)}
</FormAddWrapper>
<ConfirmModal
title='Delete Confirmation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface DefaultChallengeReviewer {
incrementalCoefficient?: number;
opportunityType?: string;
isAIReviewer: boolean;
aiWorkflowId?: string;
shouldOpenOpportunity: boolean;
createdAt: string;
createdBy: string;
Expand Down Expand Up @@ -42,4 +43,5 @@ export interface FormAddDefaultReviewer {
opportunityType?: string;
isAIReviewer: boolean;
shouldOpenOpportunity: boolean;
aiWorkflowId?: string;
}
12 changes: 12 additions & 0 deletions src/apps/admin/src/lib/services/ai-workflows.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { EnvironmentConfig } from '~/config'
import { xhrGetAsync } from '~/libs/core'

export interface AiWorkflow {
id: string;
name: string;
}

export async function getAiWorkflows(): Promise<AiWorkflow[]> {
const response = await xhrGetAsync<AiWorkflow[]>(`${EnvironmentConfig.API.V6}/workflows`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Consider adding error handling for the xhrGetAsync call to manage potential network or server errors gracefully.

return response
}
2 changes: 2 additions & 0 deletions src/apps/admin/src/lib/utils/validation-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const formSearchDefaultReviewersSchema: Yup.ObjectSchema<FormSearchDefaul

export const formAddDefaultReviewerSchema: Yup.ObjectSchema<FormAddDefaultReviewer>
= Yup.object({
aiWorkflowId: Yup.string()
.optional(),
baseCoefficient: Yup.number()
.optional()
.min(0, 'Must be non-negative'),
Expand Down
83 changes: 28 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5741,17 +5741,18 @@ axios@*, axios@^1.12.0, axios@^1.7.4:
form-data "^4.0.4"
proxy-from-env "^1.1.0"

axios@^0.25.0:
version "0.25.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.25.0.tgz#349cfbb31331a9b4453190791760a8d35b093e0a"
integrity sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==
axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
dependencies:
follow-redirects "^1.14.7"
follow-redirects "^1.14.9"
form-data "^4.0.0"

axobject-query@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
integrity sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==
axobject-query@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-4.1.0.tgz#28768c76d0e3cff21bc62a9e2d0b6ac30042a1ee"
integrity sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==

babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
Expand Down Expand Up @@ -8291,7 +8292,7 @@ es-object-atoms@^1.0.0, es-object-atoms@^1.1.1:
dependencies:
es-errors "^1.3.0"

es-set-tostringtag@^2.1.0:
es-set-tostringtag@^2.0.3, es-set-tostringtag@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz#f31dbbe0c183b00a6d26eb6325c810c0fd18bd4d"
integrity sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==
Expand All @@ -8301,16 +8302,6 @@ es-set-tostringtag@^2.1.0:
has-tostringtag "^1.0.2"
hasown "^2.0.2"

es-shim-unscopables@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz#702e632193201e3edf8713635d083d378e510241"
integrity sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==
dependencies:
es-errors "^1.3.0"
get-intrinsic "^1.2.6"
has-tostringtag "^1.0.2"
hasown "^2.0.2"

es-shim-unscopables@^1.0.2, es-shim-unscopables@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/es-shim-unscopables/-/es-shim-unscopables-1.1.0.tgz#438df35520dac5d105f3943d927549ea3b00f4b5"
Expand Down Expand Up @@ -9464,15 +9455,27 @@ flux-standard-action@^2.0.3:
lodash.isplainobject "^4.0.6"
lodash.isstring "^4.0.1"

follow-redirects@^1.0.0, follow-redirects@^1.14.7, follow-redirects@^1.15.6:
follow-redirects@^1.0.0, follow-redirects@^1.15.6:
version "1.15.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==

follow-redirects@^1.14.9, follow-redirects@^1.15.2:
version "1.15.11"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.11.tgz#777d73d72a92f8ec4d2e410eb47352a56b8e8340"
integrity sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
integrity sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==
dependencies:
is-callable "^1.1.3"

for-each@^0.3.5:
version "0.3.5"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.5.tgz#d650688027826920feeb0af747ee7b9421a41d47"
integrity sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg==
dependencies:
is-callable "^1.2.7"

Expand Down Expand Up @@ -10009,27 +10012,13 @@ has-symbols@^1.0.1, has-symbols@^1.0.3, has-symbols@^1.1.0:
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.1.0.tgz#fc9c6a783a084951d0b971fe1018de813707a338"
integrity sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==

has-tostringtag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-tostringtag/-/has-tostringtag-1.0.0.tgz#7e133818a7d394734f941e73c3d3f9291e658b25"
integrity sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==
dependencies:
has-symbols "^1.0.2"

has-tostringtag@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/has-tostringtag/-/has-tostringtag-1.0.2.tgz#2cdc42d40bef2e5b4eeab7c01a73c54ce7ab5abc"
integrity sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==
dependencies:
has-symbols "^1.0.3"

has@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796"
integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==
dependencies:
has-symbols "^1.0.3"

hasha@^5.0.0:
version "5.2.2"
resolved "https://registry.yarnpkg.com/hasha/-/hasha-5.2.2.tgz#a48477989b3b327aea3c04f53096d816d97522a1"
Expand Down Expand Up @@ -17584,7 +17573,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -17598,13 +17587,6 @@ strip-ansi@^3.0.0:
dependencies:
ansi-regex "^2.0.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.2.tgz#132875abde678c7ea8d691533f2e7e22bb744dba"
Expand Down Expand Up @@ -17974,9 +17956,9 @@ tar@^6.2.1:
mkdirp "^1.0.3"
yallist "^4.0.0"

tc-auth-lib@topcoder-platform/tc-auth-lib#1.0.27:
tc-auth-lib@topcoder-platform/tc-auth-lib#master:
version "1.0.2"
resolved "https://codeload.github.com/topcoder-platform/tc-auth-lib/tar.gz/dc5b3a29ac3b8e2a0f386fce411c6533c2f33f05"
resolved "https://codeload.github.com/topcoder-platform/tc-auth-lib/tar.gz/1c9be61eb32583beeb74f596fe58bb3ada97462d"
dependencies:
lodash "^4.17.19"

Expand Down Expand Up @@ -19641,7 +19623,7 @@ workbox-window@6.6.1:
"@types/trusted-types" "^2.0.2"
workbox-core "6.6.1"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -19659,15 +19641,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.0.1, wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down