Skip to content

Commit

Permalink
allow admins to view ratings done by users
Browse files Browse the repository at this point in the history
  • Loading branch information
nicele08 committed Aug 12, 2024
1 parent 02580fd commit 246c893
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 133 deletions.
118 changes: 66 additions & 52 deletions src/components/shared/accounts/AccountDetailTableData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,95 @@ import { roleToPath } from '@/helpers/isAuth';
import Secure from '@/helpers/secureLS';
import { RatingResponse } from '@/interfaces/rating.type';
import { HiEye } from 'react-icons/hi';
import { Link } from 'react-router-dom';
import { Link, useSearchParams } from 'react-router-dom';

const AccountDetailTableData = ({
data,
}: {
data: RatingResponse[];
}) => {
const profile = Secure.getProfile();

const [searchParams] = useSearchParams();
const role = searchParams.get('role');

return (
<>
{data.map(item => (
<tr
key={item.Ratings.id}
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
>
<td className="px-6 py-4">
{appDayjs(item.Ratings.created_at).format(dateFormat)}
</td>
{!item.title ? (
<>
{data.map(item => {
const baseLink =
profile?.role === 'ADMIN'
? `/admin/${role}`
: `/${roleToPath(profile?.role as string)}`;
const hrefLink = `${baseLink}/home?id=${
profile?.role === 'PROFESSIONAL_HEALTH_WORKER'
? item.Ratings.chat_id
: profile?.role === 'ADMIN' &&
role === 'professional-health-worker'
? item.Ratings.chat_id
: item.Ratings.question_answer_id
}`;
return (
<tr
key={item.Ratings.id}
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
>
<td className="px-6 py-4">
{appDayjs(item.Ratings.created_at).format(dateFormat)}
</td>
{!item.title ? (
<>
<td
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"
title={item.kinyarwanda_question}
>
<span className="block w-full max-w-[320px] truncate">
{item.kinyarwanda_question}
</span>
</td>
<td className="px-6 py-4">
<span className="block w-full max-w-[320px] truncate">
{item.english_question}
</span>
</td>
</>
) : (
<td
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"
title={item.kinyarwanda_question}
title={item.title}
>
<span className="block w-full max-w-[320px] truncate">
{item.kinyarwanda_question}
</span>
</td>
<td className="px-6 py-4">
<span className="block w-full max-w-[320px] truncate">
{item.english_question}
{item.title}
</span>
</td>
</>
) : (
<td
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"
title={item.title}
>
<span className="block w-full max-w-[320px] truncate">
{item.title}
</span>
</td>
)}
{/* <td
)}
{/* <td
className={`px-6 py-4 ${getRatingTextColor(
item.Ratings.rating,
)}`}
>
{item.Ratings.rating}
</td> */}
<td
className="px-6 py-4"
title={item.Ratings.comment || '-'}
>
<span className="block w-full max-w-[320px] truncate">
{item.Ratings.comment || '-'}
</span>
</td>
<td className="px-6 py-4">
<Link
to={`/${roleToPath(profile?.role as string)}/home?id=${
profile?.role === 'PROFESSIONAL_HEALTH_WORKER'
? item.Ratings.chat_id
: item.Ratings.question_answer_id
}`}
className="bg-slate-600/10 rounded-lg border p-2 font-medium flex w-fit"
<td
className="px-6 py-4"
title={item.Ratings.comment || '-'}
>
<HiEye size={24} />
</Link>
</td>
</tr>
))}
<span className="block w-full max-w-[320px] truncate">
{item.Ratings.comment || '-'}
</span>
</td>
<td className="px-6 py-4">
<Link
to={hrefLink}
className="bg-slate-600/10 rounded-lg border p-2 font-medium flex w-fit"
>
<HiEye size={24} />
</Link>
</td>
</tr>
);
})}
</>
);
};
Expand Down
10 changes: 8 additions & 2 deletions src/components/shared/accounts/AccountsTableData.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import appDayjs from '@/helpers/date';
import { roleToString } from '@/helpers/isAuth';
import { roleToPath, roleToString } from '@/helpers/isAuth';
import Secure from '@/helpers/secureLS';
import { User, allowedRoles } from '@/interfaces/user.type';
import { blockUser } from '@/redux/features/users/user.thunk';
import { useAppDispatch, useAppSelector } from '@/redux/store';
Expand All @@ -15,6 +16,7 @@ import { Link } from 'react-router-dom';
import { toast } from 'react-toastify';

const AccountsTableData = ({ data }: { data: User[] }) => {
const profile = Secure.getProfile();
const [confirmBlock, setConfirmBlock] = useState<User | null>(null);
const dispatch = useAppDispatch();
const { loading } = useAppSelector(state => state.user);
Expand Down Expand Up @@ -72,7 +74,11 @@ const AccountsTableData = ({ data }: { data: User[] }) => {
<p className="flex space-x-2 justify-end">
{allowedRoles.includes(item.role) && (
<Link
to={`/admin/accounts/${item.id}`}
to={`/admin/accounts/${item.id}${
profile?.role === 'ADMIN'
? `?role=${roleToPath(item.role)}`
: ''
}`}
state={{
fullName: item.name,
}}
Expand Down
56 changes: 33 additions & 23 deletions src/components/shared/health-worker/AnnotateConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ const AnnotateConversation = ({ data }: { data: IChat }) => {
<h1 className="pr-4 text-slate-600 text-xl font-medium font-['Inter']">
Annotate this conversation
</h1>
<p className="pl-4">
<span className="text-[#478CCA]">Progress</span>:{' '}
{profileData
? profileData.total_ratings?.toLocaleString()
: '0'}
</p>
{profileData?.role !== 'ADMIN' && (
<p className="pl-4">
<span className="text-[#478CCA]">Progress</span>:{' '}
{profileData
? profileData.total_ratings?.toLocaleString()
: '0'}
</p>
)}
</div>
{!data.ratings?.length ? (
{!data.ratings?.length && profileData?.role !== 'ADMIN' ? (
<button
type="button"
disabled={loading}
Expand Down Expand Up @@ -195,6 +197,7 @@ const AnnotateConversation = ({ data }: { data: IChat }) => {
response_helpfulness: item,
}))
}
disabled={profileData?.role === 'ADMIN'}
className="checked:bg-yellow-400 checked:ring-yellow-500 focus:ring-yellow-500"
/>
<Label
Expand Down Expand Up @@ -224,6 +227,7 @@ const AnnotateConversation = ({ data }: { data: IChat }) => {
response_correctness: item,
}))
}
disabled={profileData?.role === 'ADMIN'}
className="checked:bg-yellow-400 checked:ring-yellow-500 focus:ring-yellow-500"
/>
<Label
Expand Down Expand Up @@ -253,6 +257,7 @@ const AnnotateConversation = ({ data }: { data: IChat }) => {
response_coherence: item,
}))
}
disabled={profileData?.role === 'ADMIN'}
className="checked:bg-yellow-400 checked:ring-yellow-500 focus:ring-yellow-500"
/>
<Label
Expand Down Expand Up @@ -282,27 +287,32 @@ const AnnotateConversation = ({ data }: { data: IChat }) => {
comment: e.target.value,
}));
}}
readOnly={profileData?.role === 'ADMIN'}
className="resize-none px-4 py-3 w-full bg-white rounded-lg border outline-none border-blue-500/30 focus:border-blue-500 placeholder:text-slate-600 placeholder:text-sm font-normal font-['Inter']"
placeholder="Type your comment here..."
/>

<Button
type="submit"
label={data.ratings?.length ? 'Update' : 'Submit'}
disabled={
loading ||
!data.question_answers?.length ||
Object.keys(annotation).length < 4
}
className="uppercase mt-8 w-full disabled:bg-opacity-60 disabled:cursor-not-allowed"
/>
{profileData?.role !== 'ADMIN' && (
<Button
type="submit"
label={data.ratings?.length ? 'Update' : 'Submit'}
disabled={
loading ||
!data.question_answers?.length ||
Object.keys(annotation).length < 4
}
className="uppercase mt-8 w-full disabled:bg-opacity-60 disabled:cursor-not-allowed"
/>
)}

<Link
to={`/${roleToPath(profile?.role as string)}/dashboard`}
className="block text-center mt-6 text-slate-600 text-sm font-bold font-['Inter'] underline"
>
Annotation History
</Link>
{profileData?.role !== 'ADMIN' && (
<Link
to={`/${roleToPath(profile?.role as string)}/dashboard`}
className="block text-center mt-6 text-slate-600 text-sm font-bold font-['Inter'] underline"
>
Annotation History
</Link>
)}
</div>
</form>
</div>
Expand Down
Loading

0 comments on commit 246c893

Please sign in to comment.