Skip to content

Commit bf2a2bf

Browse files
Rajgupta36arkid15rkasya
committed
fix params and remove refresh params (#2287)
* Update docker-compose/local.yaml * UI/ux mentorship program update (#2244) * fix ui bugs * update format * fix test cases * fix test cases * update UI * update UI * update line clamp property * fix test case * Update styling --------- Co-authored-by: Kate Golovanova <[email protected]> Co-authored-by: Arkadii Yakovets <[email protected]> * fix params and remove refresh params * update direct cache * fix test cases * better exception caching * update logic Update docker-compose/local.yaml UI/ux mentorship program update (#2244) * fix ui bugs * update format * fix test cases * fix test cases * update UI * update UI * update line clamp property * fix test case * Update styling --------- Co-authored-by: Kate Golovanova <[email protected]> Co-authored-by: Arkadii Yakovets <[email protected]> * Update apollo cache logic on updating programs and modules * restore files * fix test cases * fix test cases * update button to link * fix type --------- Co-authored-by: Arkadii Yakovets <[email protected]> Co-authored-by: Kate Golovanova <[email protected]> Co-authored-by: Arkadii Yakovets <[email protected]>
1 parent 48248e9 commit bf2a2bf

File tree

12 files changed

+67
-65
lines changed

12 files changed

+67
-65
lines changed

frontend/__tests__/unit/components/ProgramCard.test.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ describe('ProgramCard', () => {
192192

193193
render(<ProgramCard program={longDescProgram} onView={mockOnView} accessLevel="user" />)
194194

195-
// Check that the full description is rendered (CSS handles the visual truncation)
196195
expect(screen.getByText(longDescription)).toBeInTheDocument()
197-
198-
// Check that the paragraph has the line-clamp-6 class
196+
expect(screen.getByText(longDescription)).toBeInTheDocument()
199197
const descriptionElement = screen.getByText(longDescription)
200198
expect(descriptionElement).toHaveClass('line-clamp-6')
201199
})
@@ -208,7 +206,6 @@ describe('ProgramCard', () => {
208206

209207
expect(screen.getByText('Short description')).toBeInTheDocument()
210208

211-
// Check that it still has line-clamp-6 class for consistency
212209
const descriptionElement = screen.getByText('Short description')
213210
expect(descriptionElement).toHaveClass('line-clamp-6')
214211
})

frontend/__tests__/unit/pages/CreateModule.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('CreateModulePage', () => {
111111

112112
await waitFor(() => {
113113
expect(mockCreateModule).toHaveBeenCalled()
114-
expect(mockPush).toHaveBeenCalledWith('/my/mentorship/programs/test-program?refresh=true')
114+
expect(mockPush).toHaveBeenCalledWith('/my/mentorship/programs/test-program')
115115
})
116116
})
117117
})

frontend/__tests__/unit/pages/EditModule.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('EditModulePage', () => {
114114

115115
await waitFor(() => {
116116
expect(mockUpdateModule).toHaveBeenCalled()
117-
expect(mockPush).toHaveBeenCalledWith('/my/mentorship/programs/test-program?refresh=true')
117+
expect(mockPush).toHaveBeenCalledWith('/my/mentorship/programs/test-program')
118118
})
119119
})
120120

frontend/src/app/my/mentorship/programs/[programKey]/edit/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const EditProgramPage = () => {
113113
timeout: 3000,
114114
})
115115

116-
router.push(`/my/mentorship/programs/${slugify(formData.name)}?refresh=true`)
116+
router.push(`/my/mentorship/programs/${slugify(formData.name)}`)
117117
} catch (err) {
118118
addToast({
119119
title: 'Update Failed',

frontend/src/app/my/mentorship/programs/[programKey]/modules/[moduleKey]/edit/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const EditModulePage = () => {
117117
variant: 'solid',
118118
timeout: 3000,
119119
})
120-
router.push(`/my/mentorship/programs/${programKey}?refresh=true`)
120+
router.push(`/my/mentorship/programs/${programKey}`)
121121
} catch (err) {
122122
handleAppError(err)
123123
}

frontend/src/app/my/mentorship/programs/[programKey]/modules/create/page.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { addToast } from '@heroui/toast'
55
import { useRouter, useParams } from 'next/navigation'
66
import { useSession } from 'next-auth/react'
77
import React, { useEffect, useState } from 'react'
8-
import { ErrorDisplay } from 'app/global-error'
8+
import { ErrorDisplay, handleAppError } from 'app/global-error'
99
import { CREATE_MODULE } from 'server/mutations/moduleMutations'
10-
import { GET_PROGRAM_ADMIN_DETAILS } from 'server/queries/programsQueries'
10+
import { GET_PROGRAM_ADMIN_DETAILS, GET_PROGRAM_AND_MODULES } from 'server/queries/programsQueries'
1111
import type { ExtendedSession } from 'types/auth'
12-
import { EXPERIENCE_LEVELS } from 'types/mentorship'
12+
import { EXPERIENCE_LEVELS, Module } from 'types/mentorship'
1313
import { parseCommaSeparated } from 'utils/parser'
1414
import LoadingSpinner from 'components/LoadingSpinner'
1515
import ModuleForm from 'components/ModuleForm'
@@ -94,7 +94,32 @@ const CreateModulePage = () => {
9494
mentorLogins: parseCommaSeparated(formData.mentorLogins),
9595
}
9696

97-
await createModule({ variables: { input } })
97+
await createModule({
98+
variables: { input },
99+
update: (cache, { data: mutationData }) => {
100+
const created = mutationData?.createModule
101+
if (!created) return
102+
try {
103+
const existing = cache.readQuery({
104+
query: GET_PROGRAM_AND_MODULES,
105+
variables: { programKey },
106+
}) as { getProgramModules: Module[] }
107+
if (existing?.getProgramModules) {
108+
cache.writeQuery({
109+
query: GET_PROGRAM_AND_MODULES,
110+
variables: { programKey },
111+
data: {
112+
...existing,
113+
getProgramModules: [created, ...existing.getProgramModules],
114+
},
115+
})
116+
}
117+
} catch (_err) {
118+
handleAppError(_err)
119+
return
120+
}
121+
},
122+
})
98123

99124
addToast({
100125
title: 'Module Created',
@@ -104,7 +129,7 @@ const CreateModulePage = () => {
104129
timeout: 3000,
105130
})
106131

107-
router.push(`/my/mentorship/programs/${programKey}?refresh=true`)
132+
router.push(`/my/mentorship/programs/${programKey}`)
108133
} catch (err) {
109134
addToast({
110135
title: 'Creation Failed',

frontend/src/app/my/mentorship/programs/[programKey]/page.tsx

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useQuery, useMutation } from '@apollo/client'
44
import { addToast } from '@heroui/toast'
55
import upperFirst from 'lodash/upperFirst'
6-
import { useParams, useSearchParams, useRouter } from 'next/navigation'
6+
import { useParams } from 'next/navigation'
77
import { useSession } from 'next-auth/react'
88
import { useEffect, useMemo, useState } from 'react'
99
import { ErrorDisplay, handleAppError } from 'app/global-error'
@@ -19,32 +19,24 @@ import LoadingSpinner from 'components/LoadingSpinner'
1919

2020
const ProgramDetailsPage = () => {
2121
const { programKey } = useParams() as { programKey: string }
22-
const searchParams = useSearchParams()
23-
const router = useRouter()
24-
const shouldRefresh = searchParams.get('refresh') === 'true'
2522

2623
const { data: session } = useSession()
2724
const username = (session as ExtendedSession)?.user?.login
2825

2926
const [program, setProgram] = useState<Program | null>(null)
3027
const [modules, setModules] = useState<Module[]>([])
31-
const [isRefetching, setIsRefetching] = useState(false)
3228

3329
const [updateProgram] = useMutation(UPDATE_PROGRAM_STATUS_MUTATION, {
3430
onError: handleAppError,
3531
})
3632

37-
const {
38-
data,
39-
refetch,
40-
loading: isQueryLoading,
41-
} = useQuery(GET_PROGRAM_AND_MODULES, {
33+
const { data, loading: isQueryLoading } = useQuery(GET_PROGRAM_AND_MODULES, {
4234
variables: { programKey },
4335
skip: !programKey,
4436
notifyOnNetworkStatusChange: true,
4537
})
4638

47-
const isLoading = isQueryLoading || isRefetching
39+
const isLoading = isQueryLoading
4840

4941
const isAdmin = useMemo(
5042
() => !!program?.admins?.some((admin) => admin.login === username),
@@ -77,7 +69,6 @@ const ProgramDetailsPage = () => {
7769
status: newStatus,
7870
},
7971
},
80-
refetchQueries: [{ query: GET_PROGRAM_AND_MODULES, variables: { programKey } }],
8172
})
8273

8374
addToast({
@@ -93,28 +84,11 @@ const ProgramDetailsPage = () => {
9384
}
9485

9586
useEffect(() => {
96-
const processResult = async () => {
97-
if (shouldRefresh) {
98-
setIsRefetching(true)
99-
try {
100-
await refetch()
101-
} finally {
102-
setIsRefetching(false)
103-
const params = new URLSearchParams(searchParams.toString())
104-
params.delete('refresh')
105-
const cleaned = params.toString()
106-
router.replace(cleaned ? `?${cleaned}` : window.location.pathname, { scroll: false })
107-
}
108-
}
109-
110-
if (data?.getProgram) {
111-
setProgram(data.getProgram)
112-
setModules(data.getProgramModules || [])
113-
}
87+
if (data?.getProgram) {
88+
setProgram(data.getProgram)
89+
setModules(data.getProgramModules || [])
11490
}
115-
116-
processResult()
117-
}, [shouldRefresh, data, refetch, router, searchParams])
91+
}, [data])
11892

11993
if (isLoading) return <LoadingSpinner />
12094

frontend/src/components/ModuleCard.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import {
77
} from '@fortawesome/free-solid-svg-icons'
88
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
99
import upperFirst from 'lodash/upperFirst'
10-
import { useRouter } from 'next/navigation'
10+
import Link from 'next/link'
1111
import { useState } from 'react'
1212
import type { Module } from 'types/mentorship'
1313
import { formatDate } from 'utils/dateFormatter'
14-
import ActionButton from 'components/ActionButton'
1514
import { TextInfoItem } from 'components/InfoItem'
1615
import SingleModuleCard from 'components/SingleModuleCard'
1716
import { TruncatedText } from 'components/TruncatedText'
@@ -69,16 +68,14 @@ const ModuleCard = ({ modules, accessLevel, admins }: ModuleCardProps) => {
6968
}
7069

7170
const ModuleItem = ({ details }: { details: Module }) => {
72-
const router = useRouter()
73-
const handleClick = () => {
74-
router.push(`${window.location.pathname}/modules/${details.key}`)
75-
}
76-
7771
return (
7872
<div className="flex h-46 w-full flex-col gap-3 rounded-lg border-1 border-gray-200 p-4 shadow-xs ease-in-out hover:shadow-md dark:border-gray-700 dark:bg-gray-800">
79-
<ActionButton onClick={handleClick}>
73+
<Link
74+
href={`${window.location.pathname}/modules/${details.key}`}
75+
className="text-start font-semibold text-blue-400 hover:underline"
76+
>
8077
<TruncatedText text={details?.name} />
81-
</ActionButton>
78+
</Link>
8279
<TextInfoItem icon={faLevelUpAlt} label="Level" value={upperFirst(details.experienceLevel)} />
8380
<TextInfoItem icon={faCalendarAlt} label="Start" value={formatDate(details.startedAt)} />
8481
<TextInfoItem

frontend/src/server/mutations/moduleMutations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const UPDATE_MODULE = gql`
1414
domains
1515
projectId
1616
mentors {
17+
id
1718
login
1819
name
1920
avatarUrl
@@ -36,6 +37,7 @@ export const CREATE_MODULE = gql`
3637
tags
3738
projectId
3839
mentors {
40+
id
3941
login
4042
name
4143
avatarUrl

frontend/src/server/mutations/programsMutations.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ import { gql } from '@apollo/client'
33
export const UPDATE_PROGRAM = gql`
44
mutation UpdateProgram($input: UpdateProgramInput!) {
55
updateProgram(inputData: $input) {
6+
id
67
key
78
name
89
description
910
status
1011
menteesLimit
12+
experienceLevels
1113
startedAt
1214
endedAt
1315
tags
1416
domains
1517
admins {
18+
id
1619
login
20+
name
21+
avatarUrl
1722
}
1823
}
1924
}
@@ -27,6 +32,7 @@ export const CREATE_PROGRAM = gql`
2732
name
2833
description
2934
menteesLimit
35+
experienceLevels
3036
startedAt
3137
endedAt
3238
tags
@@ -43,6 +49,7 @@ export const CREATE_PROGRAM = gql`
4349
export const UPDATE_PROGRAM_STATUS_MUTATION = gql`
4450
mutation updateProgramStatus($inputData: UpdateProgramStatusInput!) {
4551
updateProgramStatus(inputData: $inputData) {
52+
id
4653
key
4754
status
4855
}

0 commit comments

Comments
 (0)