From ff13c154a70be4887ee148dabeff11ebee9733fa Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Thu, 14 Nov 2024 22:02:11 +0600 Subject: [PATCH] wip --- .../CreateRoadmap/CreateRoadmapModal.tsx | 2 +- .../FeaturedListing/FeaturedListingStatus.tsx | 54 ++++++++------- .../FeaturedListing/RejectedReason.tsx | 66 ------------------- .../SubmitFeaturedListingWarning.tsx | 27 ++++++-- 4 files changed, 49 insertions(+), 100 deletions(-) delete mode 100644 src/components/CustomRoadmap/FeaturedListing/RejectedReason.tsx diff --git a/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapModal.tsx b/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapModal.tsx index a9c91e1c9..1c9d9cf9d 100644 --- a/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapModal.tsx +++ b/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapModal.tsx @@ -70,7 +70,7 @@ export interface RoadmapDocument { }; featuredListStatus?: AllowedRoadmapFeaturedListStatus; - featuredListReason?: string; + featuredListRejectedReason?: string; featuredListSubmittedAt?: Date; featuredListApprovedAt?: Date; diff --git a/src/components/CustomRoadmap/FeaturedListing/FeaturedListingStatus.tsx b/src/components/CustomRoadmap/FeaturedListing/FeaturedListingStatus.tsx index b9b4a511c..71c4f8865 100644 --- a/src/components/CustomRoadmap/FeaturedListing/FeaturedListingStatus.tsx +++ b/src/components/CustomRoadmap/FeaturedListing/FeaturedListingStatus.tsx @@ -12,38 +12,36 @@ export function FeaturedListingStatus(props: FeaturedListingStatusProps) { const { featuredListStatus = 'idle' } = currentRoadmap; const [showSubmitWarning, setShowSubmitWarning] = useState(false); + const currentLabel = { + idle: 'Submit for Featured Listing', + submitted: 'Submitted', + approved: 'Approved', + rejected: 'Rejected', + rejected_with_reason: 'Rejected with Reason', + }[featuredListStatus]; + return ( <> - {featuredListStatus === 'idle' && ( - <> - {showSubmitWarning && ( - setShowSubmitWarning(false)} - /> - )} - - - - )} - - {featuredListStatus === 'submitted' && ( - Submitted - )} - - {featuredListStatus === 'approved' && ( - Approved - )} - - {featuredListStatus === 'rejected' && ( - Rejected + {showSubmitWarning && ( + { + setShowSubmitWarning(false); + }} + /> )} - {featuredListStatus === 'rejected_with_reason' && <>} + ); } diff --git a/src/components/CustomRoadmap/FeaturedListing/RejectedReason.tsx b/src/components/CustomRoadmap/FeaturedListing/RejectedReason.tsx deleted file mode 100644 index 1ab6e2efd..000000000 --- a/src/components/CustomRoadmap/FeaturedListing/RejectedReason.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { useMutation } from '@tanstack/react-query'; -import { Modal } from '../../Modal'; -import { queryClient } from '../../../stores/query-client'; -import { httpPost } from '../../../lib/query-http'; -import { useStore } from '@nanostores/react'; -import { currentRoadmap } from '../../../stores/roadmap'; -import { useToast } from '../../../hooks/use-toast'; - -type RejectedReasonProps = { - onClose: () => void; -}; - -export function RejectedReason(props: RejectedReasonProps) { - const { onClose } = props; - - const toast = useToast(); - const $currentRoadmap = useStore(currentRoadmap); - - const submit = useMutation( - { - mutationFn: async () => { - return httpPost( - `/v1-submit-for-featured-listing/${$currentRoadmap?._id}`, - {}, - ); - }, - onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: ['get-roadmap'], - }); - - onClose(); - }, - onError: (error) => { - toast.error(error?.message || 'Something went wrong'); - }, - }, - queryClient, - ); - - return ( - -
-

Rejected Reason

-

{$currentRoadmap?.featuredListReason}

- -
- - -
-
-
- ); -} diff --git a/src/components/CustomRoadmap/FeaturedListing/SubmitFeaturedListingWarning.tsx b/src/components/CustomRoadmap/FeaturedListing/SubmitFeaturedListingWarning.tsx index e73eced03..1f8a69e87 100644 --- a/src/components/CustomRoadmap/FeaturedListing/SubmitFeaturedListingWarning.tsx +++ b/src/components/CustomRoadmap/FeaturedListing/SubmitFeaturedListingWarning.tsx @@ -40,14 +40,27 @@ export function SubmitFeaturedListingWarning( queryClient, ); + const { featuredListStatus = 'idle', featuredListRejectedReason } = + $currentRoadmap || {}; + return (
-

Featured Listing

+

+ {featuredListStatus === 'rejected_with_reason' + ? 'Rejected Reason' + : 'Featured Listing'} +

- Submitting your roadmap for a featured listing will make it visible to - everyone on the platform.{' '} - Are you sure? + {featuredListStatus === 'rejected_with_reason' && + featuredListRejectedReason} + {featuredListStatus === 'idle' && ( + <> + Submitting your roadmap for a featured listing will make it + visible to everyone on the platform.{' '} + Are you sure? + + )}

@@ -63,7 +76,11 @@ export function SubmitFeaturedListingWarning( disabled={submit.isPending} onClick={() => submit.mutate()} > - {submit.isPending ? 'Submitting...' : 'Submit'} + {submit.isPending + ? 'Submitting...' + : featuredListStatus === 'rejected_with_reason' + ? 'Resubmit' + : 'Submit'}