-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add page satisfaction feedback banner (Vertex app) #3502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9fe34fe
feat: add page satisfaction feedback banner component
TrivCodez 0fdecc5
fix: address CodeRabbit review comments
TrivCodez 4449add
feat: integrate page satisfaction banner into authenticated layout
TrivCodez e8a027c
fix: address all PR feedback for page satisfaction banner
TrivCodez c89fd13
fix: replace toast with useBanner hook and fix banner positioning
TrivCodez d7d9781
fix: change banner from fixed to sticky positioning to respect layout…
TrivCodez a8f5ff7
Merge branch 'staging' into pr/3491
Codebmk 3df10b9
position page satisfaction banner at bottom
Codebmk 075d9f1
Update layout.tsx
Codebmk 4708fa9
show global banner
Codebmk b4bca89
move banner within layout
Codebmk ec97fd8
Update changelog.md
Codebmk 1cf1f4d
Update page-satisfaction-banner.tsx
Codebmk 72097a2
fix 150ms delay
Codebmk 78f06a8
update category top
Codebmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
275 changes: 275 additions & 0 deletions
275
src/vertex/components/features/feedback/page-satisfaction-banner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,275 @@ | ||
| 'use client'; | ||
|
|
||
| import React, { useState } from 'react'; | ||
| import { ThumbsUp, ThumbsDown, MessageSquare } from 'lucide-react'; | ||
| import { openFeedbackDialog } from './feedback-dialog'; | ||
| import { feedbackService } from '@/core/apis/feedback'; | ||
| import { useUserContext } from '@/core/hooks/useUserContext'; | ||
| import { useBanner } from '@/context/banner-context'; | ||
| import ReusableDialog from '@/components/shared/dialog/ReusableDialog'; | ||
| import ReusableInputField from '@/components/shared/inputfield/ReusableInputField'; | ||
| import ReusableButton from '@/components/shared/button/ReusableButton'; | ||
| import { getApiErrorMessage } from '@/core/utils/getApiErrorMessage'; | ||
| import { usePathname } from 'next/navigation'; | ||
|
|
||
| const NEGATIVE_REASONS = [ | ||
| 'Confusing', | ||
| 'Not helpful', | ||
| 'Missing features', | ||
| 'Missing or limited data', | ||
| 'I encountered technical issues', | ||
| 'Other', | ||
| ]; | ||
|
|
||
| const POSITIVE_REASONS = [ | ||
| 'Informative', | ||
| 'Actionable', | ||
| 'Makes my job easier', | ||
| 'Ease of use', | ||
| 'Other', | ||
| ]; | ||
|
|
||
| interface FeedbackModalProps { | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| onSubmit: (rating: number, reason: string, message: string) => Promise<boolean>; | ||
| isSubmitting: boolean; | ||
| type: 'positive' | 'negative'; | ||
| } | ||
|
|
||
| const FeedbackModal: React.FC<FeedbackModalProps> = ({ | ||
| isOpen, | ||
| onClose, | ||
| onSubmit, | ||
| isSubmitting, | ||
| type, | ||
| }) => { | ||
| const [reason, setReason] = useState(''); | ||
| const [message, setMessage] = useState(''); | ||
| const { showBanner } = useBanner(); | ||
|
|
||
| const reasons = type === 'positive' ? POSITIVE_REASONS : NEGATIVE_REASONS; | ||
|
|
||
| const handleSubmit = async () => { | ||
| if (!reason) { | ||
| return; | ||
| } | ||
| const submitted = await onSubmit( | ||
| type === 'positive' ? 5 : 1, | ||
| reason, | ||
| message | ||
| ); | ||
| if (!submitted) return; | ||
| setReason(''); | ||
| setMessage(''); | ||
| onClose(); | ||
| setTimeout(() => { | ||
| showBanner({ | ||
| severity: 'success', | ||
| title: 'Thank you for your feedback!', | ||
| message: 'Your input helps us improve the platform.', | ||
| }); | ||
| }, 300); | ||
| }; | ||
|
|
||
| return ( | ||
| <ReusableDialog | ||
| isOpen={isOpen} | ||
| onClose={() => { | ||
| setReason(''); | ||
| setMessage(''); | ||
| onClose(); | ||
| }} | ||
| title="Why did you choose this rating?" | ||
| size="md" | ||
| showFooter | ||
| primaryAction={{ | ||
| label: isSubmitting ? 'Sending...' : 'Submit', | ||
| onClick: handleSubmit, | ||
| disabled: isSubmitting || !reason, | ||
| }} | ||
| secondaryAction={{ | ||
| label: 'Cancel', | ||
| onClick: () => { | ||
| setReason(''); | ||
| setMessage(''); | ||
| onClose(); | ||
| }, | ||
| disabled: isSubmitting, | ||
| variant: 'outline', | ||
| }} | ||
| > | ||
| <div className="flex flex-col gap-4 py-4"> | ||
| <div className="space-y-2"> | ||
| <label className="text-sm font-medium text-gray-700 dark:text-gray-200"> | ||
| Select a reason | ||
| </label> | ||
| <div className="space-y-2"> | ||
| {reasons.map((r) => ( | ||
| <label | ||
| key={r} | ||
| className="flex items-center gap-2 cursor-pointer" | ||
| > | ||
| <input | ||
| type="radio" | ||
| name="reason" | ||
| value={r} | ||
| checked={reason === r} | ||
| onChange={() => setReason(r)} | ||
| className="h-4 w-4 text-primary" | ||
| /> | ||
| <span className="text-sm text-gray-700 dark:text-gray-300"> | ||
| {r} | ||
| </span> | ||
| </label> | ||
| ))} | ||
| </div> | ||
| </div> | ||
|
|
||
| <ReusableInputField | ||
| as="textarea" | ||
| id="message" | ||
| label="Any additional feedback about this page you would like to share with us?" | ||
| value={message} | ||
| onChange={(event) => setMessage(event.target.value)} | ||
| placeholder="Your feedback helps us improve..." | ||
| rows={5} | ||
| description="Please don't include any sensitive information" | ||
| /> | ||
| </div> | ||
| </ReusableDialog> | ||
| ); | ||
| }; | ||
|
|
||
| export const PageSatisfactionBanner: React.FC = () => { | ||
| const [modalType, setModalType] = useState<'positive' | 'negative' | null>(null); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const pathname = usePathname(); | ||
| const { userDetails } = useUserContext(); | ||
| const { showBanner } = useBanner(); | ||
|
|
||
| const getPageName = () => { | ||
| if (!pathname) return 'this page'; | ||
| const parts = pathname.split('/').filter(Boolean); | ||
| const lastPart = parts[parts.length - 1] || 'home'; | ||
| return lastPart | ||
| .split('-') | ||
| .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
| .join(' '); | ||
| }; | ||
|
|
||
| const handleSubmitFeedback = async ( | ||
| rating: number, | ||
| reason: string, | ||
| message: string | ||
| ): Promise<boolean> => { | ||
| const userEmail = userDetails?.email || userDetails?.userName || ''; | ||
|
|
||
| if (!userEmail) { | ||
| showBanner({ | ||
| severity: 'error', | ||
| title: 'Unable to identify your account', | ||
| message: 'Please try again in a moment.', | ||
| scoped: true, | ||
| }); | ||
| return false; | ||
| } | ||
|
|
||
| setIsSubmitting(true); | ||
|
|
||
| try { | ||
| const metadata = { | ||
| page: pathname || window.location.pathname, | ||
| reason, | ||
| browser: | ||
| typeof window !== 'undefined' | ||
| ? navigator.userAgent.slice(0, 80) | ||
| : 'Unknown', | ||
| appVersion: process.env.NEXT_PUBLIC_APP_VERSION || '1.0.0', | ||
| }; | ||
|
|
||
| await feedbackService.submitFeedback({ | ||
| email: userEmail, | ||
| subject: `Page Satisfaction: ${getPageName()}`, | ||
| message: message || `Rating: ${rating}/5, Reason: ${reason}`, | ||
| rating, | ||
| category: 'page_satisfaction', | ||
| platform: 'web', | ||
| app: 'vertex', | ||
| metadata, | ||
| }); | ||
|
|
||
|
|
||
| return true; | ||
| } catch (error) { | ||
| showBanner({ | ||
| severity: 'error', | ||
| title: 'Failed to submit feedback', | ||
| message: error instanceof Error ? getApiErrorMessage(error) : 'An error occurred while submitting feedback', | ||
| scoped: true, | ||
| }); | ||
| return false; | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="w-full border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 py-4 px-4"> | ||
| <div className="max-w-7xl mx-auto flex flex-col sm:flex-row items-center justify-between gap-4"> | ||
| <div className="text-center sm:text-left"> | ||
| <h3 className="text-sm font-semibold text-gray-900 dark:text-white"> | ||
| Overall, how satisfied are you with {getPageName()}? | ||
| </h3> | ||
| </div> | ||
|
|
||
| <div className="flex items-center gap-3"> | ||
| <ReusableButton | ||
| variant="text" | ||
| onClick={() => setModalType('positive')} | ||
| className="p-2 hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors" | ||
| aria-label="Satisfied" | ||
| > | ||
| <ThumbsUp className="h-6 w-6 text-gray-600 dark:text-gray-300" /> | ||
| </ReusableButton> | ||
|
|
||
| <ReusableButton | ||
| variant="text" | ||
| onClick={() => setModalType('negative')} | ||
| className="p-2 hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors" | ||
| aria-label="Not satisfied" | ||
| > | ||
| <ThumbsDown className="h-6 w-6 text-gray-600 dark:text-gray-300" /> | ||
| </ReusableButton> | ||
|
|
||
| <ReusableButton | ||
| variant="text" | ||
| onClick={openFeedbackDialog} | ||
| className="p-2 hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors" | ||
| aria-label="Comment" | ||
| > | ||
| <MessageSquare className="h-6 w-6 text-gray-600 dark:text-gray-300" /> | ||
| </ReusableButton> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <FeedbackModal | ||
| isOpen={modalType === 'positive'} | ||
| onClose={() => setModalType(null)} | ||
| onSubmit={handleSubmitFeedback} | ||
| isSubmitting={isSubmitting} | ||
| type="positive" | ||
| /> | ||
|
|
||
| <FeedbackModal | ||
| isOpen={modalType === 'negative'} | ||
| onClose={() => setModalType(null)} | ||
| onSubmit={handleSubmitFeedback} | ||
| isSubmitting={isSubmitting} | ||
| type="negative" | ||
| /> | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.