Skip to content

Commit 395ded4

Browse files
committed
#1650 - userCurrentUser
1 parent 3ffc8c4 commit 395ded4

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/frontend/src/pages/ChangeRequestDetailPage/ProposedSolutionsList.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import { ProposedSolution } from 'shared';
6+
import { ProposedSolution, isGuest } from 'shared';
77
import ProposedSolutionForm from './ProposedSolutionForm';
88
import { useState } from 'react';
99
import { useCreateProposeSolution } from '../../hooks/change-requests.hooks';
@@ -16,6 +16,7 @@ import DetailDisplay from '../../components/DetailDisplay';
1616
import { weeksPipe } from '../../utils/pipes';
1717
import AttachMoneyIcon from '@mui/icons-material/AttachMoney';
1818
import ScheduleIcon from '@mui/icons-material/Schedule';
19+
import { useCurrentUser } from '../../hooks/users.hooks';
1920

2021
interface ProposedSolutionsListProps {
2122
proposedSolutions: ProposedSolution[];
@@ -25,15 +26,15 @@ interface ProposedSolutionsListProps {
2526

2627
const ProposedSolutionsList: React.FC<ProposedSolutionsListProps> = ({ proposedSolutions, crReviewed, crId }) => {
2728
const [showEditableForm, setShowEditableForm] = useState<boolean>(false);
28-
const auth = useAuth();
29+
const user = useCurrentUser();
2930
const { isLoading, isError, error, mutateAsync } = useCreateProposeSolution();
3031
const toast = useToast();
3132
const theme = useTheme();
3233

33-
if (isLoading || !auth.user) return <LoadingIndicator />;
34+
if (isLoading) return <LoadingIndicator />;
3435
if (isError) return <ErrorPage message={error?.message} />;
3536

36-
const { userId } = auth.user;
37+
const { userId } = user;
3738

3839
const addProposedSolution = async (data: ProposedSolution) => {
3940
setShowEditableForm(false);
@@ -66,14 +67,16 @@ const ProposedSolutionsList: React.FC<ProposedSolutionsListProps> = ({ proposedS
6667
) : null}
6768
<Box display="flex" justifyContent="space-between" mb="10px">
6869
<Typography variant="h5">Proposed Solutions</Typography>
69-
<Button
70-
onClick={() => setShowEditableForm(true)}
71-
variant="contained"
72-
color="success"
73-
sx={{ maxHeight: { xs: 105, md: 35 }, height: {} }}
74-
>
75-
+ Add Solution
76-
</Button>
70+
{crReviewed === undefined && !isGuest(user.role) && (
71+
<Button
72+
onClick={() => setShowEditableForm(true)}
73+
variant="contained"
74+
color="success"
75+
sx={{ maxHeight: { xs: 105, md: 35 }, height: {} }}
76+
>
77+
+ Add Solution
78+
</Button>
79+
)}
7780
</Box>
7881
{proposedSolutions.map((proposedSolution) => (
7982
<Grid

0 commit comments

Comments
 (0)