Skip to content

Commit

Permalink
mods cant approve their own request
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonnorsworthy committed Sep 21, 2024
1 parent a43ca0f commit b2d980d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
24 changes: 16 additions & 8 deletions src/modals/EditSuggestions/EditSuggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { DEFAULT_IMG_URL } from '@/constants';

interface ModalProps {
onClose: () => void;
onDeleteSuggestion: () => void;
onDeleteSuggestion?: () => void;
onCreateQuest: (newQuest: convertSuggestionIntoQuestBodyRequest) => void;
suggestion: Suggestion;
categories: Category[];
viewOnly?: boolean;
}

const EditSuggestion: React.FC<ModalProps> = (props) => {
Expand All @@ -19,7 +20,8 @@ const EditSuggestion: React.FC<ModalProps> = (props) => {
onDeleteSuggestion,
onCreateQuest,
suggestion,
categories
categories,
viewOnly = false
} = props;

const [previewQuest, setPreviewQuest] = useState(true);
Expand Down Expand Up @@ -152,23 +154,29 @@ const EditSuggestion: React.FC<ModalProps> = (props) => {
onClick={onClose}>
close
</Button>
<Button
type='cancel'
onClick={onDeleteSuggestion}
>
delete
</Button>
{
onDeleteSuggestion &&
<Button
type='cancel'
disabled={viewOnly}
onClick={onDeleteSuggestion}
>
delete
</Button>
}
</div>
<div className="flex flex-col w-full gap-2 mt-2 sm:w-fit sm:mt-0 sm:flex-row sm:justify-end">
<Button
type="info"
disabled={viewOnly}
onClick={() => setPreviewQuest(prev => !prev)}>
{previewQuest ? 'edit' : 'preview'}
</Button>
{
onCreateQuest &&
<Button
type="confirm"
disabled={viewOnly}
onClick={() => onCreateQuest({
title,
description,
Expand Down
7 changes: 4 additions & 3 deletions src/pages/moderator/ModeratorSuggestionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Loader from "@/components/Loader";

const ModeratorSuggestionsPage = () => {
const navigate = useNavigate();
const { accessToken } = useAuth();
const { accessToken, user } = useAuth();

const [suggestions, setSuggestions] = useState<Suggestion[]>([]);
const [page, setPage] = useState(1);
Expand Down Expand Up @@ -94,7 +94,7 @@ const ModeratorSuggestionsPage = () => {
})
};

const handleDeleteSuggestion = async () => {
const onDeleteSuggestion = async () => {
const onConfirm = () => {
try {
if (!selectedSuggestion) return;
Expand Down Expand Up @@ -192,8 +192,9 @@ const ModeratorSuggestionsPage = () => {
onClose={handleCloseSuggestion}
suggestion={selectedSuggestion}
onCreateQuest={handleCreateQuest}
onDeleteSuggestion={handleDeleteSuggestion}
onDeleteSuggestion={onDeleteSuggestion}
categories={categories}
viewOnly={user?.username === selectedSuggestion.username}
/>
</Modal>
}
Expand Down

0 comments on commit b2d980d

Please sign in to comment.