Skip to content

Commit aab03b5

Browse files
authored
Merge pull request #1237 from topcoder-platform/feat/review-edit-integration
Review Edit Integration
2 parents bb61977 + effae6e commit aab03b5

File tree

95 files changed

+3083
-2065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3083
-2065
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { TcUniNavFn } from 'universal-navigation'
1+
import { getTcUniNav } from '~/apps/platform/src/utils'
22

33
import { CES_SURVEY_ID } from '../config'
44

5-
declare let tcUniNav: TcUniNavFn
6-
75
export function triggerSurvey(): void {
8-
tcUniNav('triggerFlow', CES_SURVEY_ID, {})
6+
getTcUniNav()?.('triggerFlow', CES_SURVEY_ID, {})
97
}

src/apps/platform/src/components/app-footer/AppFooter.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { FC, MutableRefObject, useEffect, useRef } from 'react'
2-
import type { TcUniNavFn } from 'universal-navigation'
32

4-
declare let tcUniNav: TcUniNavFn
3+
import { getTcUniNav } from '../../utils'
54

65
const APP_FOOTER_EL_ID: string = 'footer-nav-el'
76

@@ -22,7 +21,7 @@ const AppFooter: FC<{}> = () => {
2221
return
2322
}
2423

25-
tcUniNav(
24+
getTcUniNav()?.(
2625
'init',
2726
APP_FOOTER_EL_ID,
2827
{

src/apps/platform/src/components/app-header/AppHeader.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useState,
1212
} from 'react'
1313
import { NavigateFunction, useNavigate } from 'react-router-dom'
14-
import type { AuthUser as NavAuthUser, TcUniNavFn } from 'universal-navigation'
14+
import type { AuthUser as NavAuthUser } from 'universal-navigation'
1515
import classNames from 'classnames'
1616

1717
import { EnvironmentConfig, PageSubheaderPortalId } from '~/config'
@@ -25,9 +25,10 @@ import {
2525
} from '~/libs/core'
2626
import { ConfigContextValue, useConfigContext } from '~/libs/shared'
2727

28+
import { getTcUniNav } from '../../utils'
29+
2830
import UniNavSnippet from './universal-nav-snippet'
2931

30-
declare let tcUniNav: TcUniNavFn
3132
UniNavSnippet(EnvironmentConfig.URLS.UNIVERSAL_NAV)
3233

3334
interface NavigationRequest {
@@ -86,7 +87,7 @@ const AppHeader: FC<{}> = () => {
8687

8788
headerInit.current = true
8889

89-
tcUniNav(
90+
getTcUniNav()?.(
9091
'init',
9192
navElementId,
9293
{
@@ -116,7 +117,7 @@ const AppHeader: FC<{}> = () => {
116117
// update uni-nav's tool details
117118
useEffect(() => {
118119

119-
tcUniNav(
120+
getTcUniNav()?.(
120121
'update',
121122
navElementId,
122123
{
@@ -139,7 +140,7 @@ const AppHeader: FC<{}> = () => {
139140
return
140141
}
141142

142-
tcUniNav(
143+
getTcUniNav()?.(
143144
'update',
144145
navElementId,
145146
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './other'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TcUniNavFn } from 'universal-navigation'
2+
3+
declare let tcUniNav: TcUniNavFn
4+
5+
/**
6+
* Get tcUniNav
7+
* @returns tcUniNav
8+
*/
9+
export function getTcUniNav(): TcUniNavFn | undefined {
10+
if (typeof tcUniNav === 'undefined') {
11+
return undefined
12+
}
13+
14+
return tcUniNav
15+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { TcUniNavFn } from 'universal-navigation'
1+
import { getTcUniNav } from '~/apps/platform/src/utils'
22

33
import { CES_SURVEY_ID } from '../config'
44

5-
declare let tcUniNav: TcUniNavFn
6-
75
export function triggerSurvey(): void {
8-
tcUniNav('triggerFlow', CES_SURVEY_ID, {})
6+
getTcUniNav()?.('triggerFlow', CES_SURVEY_ID, {})
97
}

src/apps/review/src/config/index.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ export const WINNERS = 'Winners'
7676
export const TAB = 'tab'
7777
export const FINISHTAB = [WINNERS]
7878
export const WITHOUT_APPEAL = [DESIGN, FIRST2FINISH]
79+
80+
export const NO_RESOURCE_ID = 'noResource'

src/apps/review/src/lib/components/Appeal/Appeal.tsx

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
/**
22
* AppealComment.
33
*/
4-
import { FC, useCallback, useState } from 'react'
4+
import { FC, useCallback, useContext, useEffect, useMemo, useState } from 'react'
55
import {
66
Controller,
77
ControllerRenderProps,
88
useForm,
99
UseFormReturn,
1010
} from 'react-hook-form'
11-
import _, { bind, includes } from 'lodash'
11+
import { get } from 'lodash'
1212
import classNames from 'classnames'
1313

1414
import { yupResolver } from '@hookform/resolvers/yup'
1515

1616
import { MarkdownReview } from '../MarkdownReview'
1717
import { FieldMarkdownEditor } from '../FieldMarkdownEditor'
18-
import { FormAppealResponse } from '../../models'
19-
import { formAppealResponseSchema } from '../../utils'
20-
import { ADMIN, COPILOT, FINISHTAB, ITERATIVE_REVIEW, TAB } from '../../../config/index.config'
18+
import { AppealInfo, ChallengeDetailContextModel, FormAppealResponse } from '../../models'
19+
import { formAppealResponseSchema, isAppealsPhase } from '../../utils'
20+
import { ReviewItemComment } from '../../models/ReviewItemComment.model'
21+
import { ChallengeDetailContext } from '../../contexts'
2122

2223
import styles from './Appeal.module.scss'
2324

2425
interface Props {
2526
className?: string
26-
role?: string
27+
appealInfo?: AppealInfo
28+
commentItem: ReviewItemComment
29+
isSavingAppeal: boolean
30+
addAppeal: (
31+
content: string,
32+
commentItem: ReviewItemComment,
33+
success: () => void,
34+
) => void
35+
doDeleteAppeal: (
36+
appealInfo: AppealInfo | undefined,
37+
success: () => void,
38+
) => void
2739
}
2840

2941
export const AppealComment: FC<Props> = (props: Props) => {
3042
const [appealResponse, setAppealResponse] = useState('')
3143
const [showResponseForm, setShowResponseForm] = useState(false)
32-
const [showAppealResponse, setShowAppealResponse] = useState(false)
44+
45+
const { challengeInfo }: ChallengeDetailContextModel = useContext(
46+
ChallengeDetailContext,
47+
)
48+
const canAddAppeal = useMemo(() => isAppealsPhase(challengeInfo), [challengeInfo])
3349

3450
const {
3551
handleSubmit,
@@ -44,29 +60,54 @@ export const AppealComment: FC<Props> = (props: Props) => {
4460
})
4561

4662
const onSubmit = useCallback((data: FormAppealResponse) => {
47-
setAppealResponse(data.response)
48-
setShowResponseForm(false)
49-
setShowAppealResponse(true)
50-
}, [])
63+
props.addAppeal(data.response, props.commentItem, () => {
64+
setAppealResponse(data.response)
65+
setShowResponseForm(false)
66+
})
67+
}, [props.commentItem])
5168

52-
if (includes(FINISHTAB, sessionStorage.getItem(TAB))) {
53-
return <></>
54-
}
69+
useEffect(() => {
70+
if (props.appealInfo) {
71+
setAppealResponse(props.appealInfo.content)
72+
}
73+
}, [props.appealInfo])
5574

5675
return (
5776
<div className={classNames(styles.container, props.className)}>
58-
{showAppealResponse && (
77+
{appealResponse && !showResponseForm && (
5978
<div className={styles.blockAppealComment}>
6079
<span className={styles.textTitle}>Appeal Comment</span>
6180
<MarkdownReview value={appealResponse} />
81+
{canAddAppeal && (
82+
<div className={styles.blockBtns}>
83+
<button
84+
onClick={function onClick() {
85+
setShowResponseForm(true)
86+
}}
87+
className='filledButton'
88+
type='button'
89+
disabled={props.isSavingAppeal}
90+
>
91+
Edit Appeal
92+
</button>
93+
<button
94+
onClick={function onClick() {
95+
props.doDeleteAppeal(props.appealInfo, () => {
96+
setAppealResponse('')
97+
})
98+
}}
99+
type='button'
100+
className='cancelButton'
101+
disabled={props.isSavingAppeal}
102+
>
103+
Delete
104+
</button>
105+
</div>
106+
)}
62107
</div>
63108
)}
64109

65-
{!showResponseForm
66-
&& !showAppealResponse
67-
&& !includes(FINISHTAB, sessionStorage.getItem(TAB))
68-
&& !includes(sessionStorage.getItem(TAB), ITERATIVE_REVIEW)
69-
&& !includes([COPILOT, ADMIN], props.role) && (
110+
{!appealResponse && !showResponseForm && canAddAppeal && (
70111
<button
71112
type='button'
72113
className='borderButton'
@@ -95,23 +136,31 @@ export const AppealComment: FC<Props> = (props: Props) => {
95136
}) {
96137
return (
97138
<FieldMarkdownEditor
139+
initialValue={appealResponse}
98140
className={styles.markdownEditor}
99141
onChange={controlProps.field.onChange}
100142
showBorder
101143
onBlur={controlProps.field.onBlur}
102-
error={_.get(errors, 'response.message')}
144+
error={get(errors, 'response.message')}
145+
disabled={props.isSavingAppeal}
103146
/>
104147
)
105148
}}
106149
/>
107150
<div className={styles.blockBtns}>
108-
<button className='filledButton' type='submit'>
151+
<button
152+
disabled={props.isSavingAppeal}
153+
className='filledButton'
154+
type='submit'
155+
>
109156
Submit Appeal
110157
</button>
111158
<button
112159
type='button'
113160
className='borderButton'
114-
onClick={bind(setShowResponseForm, undefined, false)}
161+
onClick={function onClick() {
162+
setShowResponseForm(false)
163+
}}
115164
>
116165
Cancel
117166
</button>

src/apps/review/src/lib/components/AppealComment/AppealComment.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,10 @@
7373
line-height: 20px;
7474
}
7575
}
76+
77+
.blockReaponseAppealHeader {
78+
display: flex;
79+
align-items: center;
80+
justify-content: space-between;
81+
gap: 10px;
82+
}

0 commit comments

Comments
 (0)