Skip to content

Commit 2a325db

Browse files
committed
fix(ue): hide rating section when user has no rights
1 parent 750c9c6 commit 2a325db

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed

src/app/ues/[code]/page.tsx

+49-43
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import ExamList from '@/components/ues/ExamList';
2424
import ExamSender from '@/components/ues/ExamSender';
2525
import Tooltip from '@/components/UI/Tooltip';
2626
import Link from '@/components/UI/Link';
27+
import { UserType } from '@/module/user';
2728

2829
export default function UEDetailsPage() {
2930
usePageSettings({});
3031
const params = useParams<{ code: string }>();
3132
const { t } = useAppTranslation();
3233
const logged = useAppSelector((state) => state.session.logged);
34+
const type = useAppSelector((state) => state.user?.type);
3335
const [ue, refreshUE] = useUE(params.code as string);
3436
const criteria = useUERateCriteria();
3537
const [myRates, setMyRates] = useGetRate(params.code);
@@ -192,50 +194,54 @@ export default function UEDetailsPage() {
192194
annalSemesters={annalSemesters}
193195
annalTypes={annalTypes}
194196
/>
195-
<div className={styles.thoughts}>
196-
<h2>{t('ues:detailed.rates.title')}</h2>
197-
<div className={[styles.rates, !criteria && styles.error].filter((c) => c).join(' ')}>
198-
{criteria
199-
? Object.entries(ue.starVotes).map(([id, value]) => {
200-
const myRate = myRates?.find((rate) => rate.criterionId === id);
201-
return (
202-
<div key={id} className={styles.criterion}>
203-
<h3>{criteria.find((criterion): criterion is UERateCriterion => criterion.id === id)?.name}</h3>
204-
<StarRating stars={5} value={value} />
205-
{myRates && (
206-
<>
207-
<StarRating
208-
stars={5}
209-
value={myRate?.value ?? 0}
210-
onClick={(rate) => onRate(id as string, !!myRate, rate)}
211-
/>
212-
{myRate && (
213-
<Button className={styles.deleteRate} onClick={() => deleteRate(id as string)}>
214-
{t('ues:detailed.rates.delete')}
215-
</Button>
216-
)}
217-
</>
218-
)}
219-
</div>
220-
);
221-
})
222-
: t('ues:detailed.rates.error')}
197+
{logged && (type === UserType.STUDENT || type === UserType.FORMER_STUDENT) && (
198+
<div className={styles.thoughts}>
199+
<h2>{t('ues:detailed.rates.title')}</h2>
200+
<div className={[styles.rates, !criteria && styles.error].filter((c) => c).join(' ')}>
201+
{criteria && ue.starVotes
202+
? Object.entries(ue.starVotes).map(([id, value]) => {
203+
const myRate = myRates?.find((rate) => rate.criterionId === id);
204+
return (
205+
<div key={id} className={styles.criterion}>
206+
<h3>
207+
{criteria.find((criterion): criterion is UERateCriterion => criterion.id === id)?.name}
208+
</h3>
209+
<StarRating stars={5} value={value} />
210+
{myRates && (
211+
<>
212+
<StarRating
213+
stars={5}
214+
value={myRate?.value ?? 0}
215+
onClick={(rate) => onRate(id as string, !!myRate, rate)}
216+
/>
217+
{myRate && (
218+
<Button className={styles.deleteRate} onClick={() => deleteRate(id as string)}>
219+
{t('ues:detailed.rates.delete')}
220+
</Button>
221+
)}
222+
</>
223+
)}
224+
</div>
225+
);
226+
})
227+
: t('ues:detailed.rates.error')}
228+
</div>
229+
{logged && (type === UserType.STUDENT || type === UserType.FORMER_STUDENT) ? (
230+
<>
231+
<div className={styles.writeComment}>
232+
{t('ues:detailed.comments.write')}
233+
<TextArea value={writtingComment} onChange={setWrittingComment} />
234+
<Button onClick={() => sendComment(api, ue.code, writtingComment, false)}>
235+
{t('ues:detailed.comments.write.send')}
236+
</Button>
237+
</div>
238+
<Comments code={params.code} />
239+
</>
240+
) : (
241+
t('ues:detailed.comments.loginRequired')
242+
)}
223243
</div>
224-
{logged ? (
225-
<>
226-
<div className={styles.writeComment}>
227-
{t('ues:detailed.comments.write')}
228-
<TextArea value={writtingComment} onChange={setWrittingComment} />
229-
<Button onClick={() => sendComment(api, ue.code, writtingComment, false)}>
230-
{t('ues:detailed.comments.write.send')}
231-
</Button>
232-
</div>
233-
<Comments code={params.code as string} />
234-
</>
235-
) : (
236-
t('ues:detailed.comments.loginRequired')
237-
)}
238-
</div>
244+
)}
239245
</>
240246
) : (
241247
<ExamSender

0 commit comments

Comments
 (0)