MCPcopy Create free account
hub / github.com/dailydotdev/apps / FeedbackModal

Function FeedbackModal

packages/shared/src/components/modals/FeedbackModal.tsx:54–444  ·  view source on GitHub ↗
({
  onRequestClose,
  initialCategory = FeedbackCategory.BugReport,
  initialDescription = '',
  ...props
}: FeedbackModalProps)

Source from the content-addressed store, hash-verified

52const FEEDBACK_MODAL_OVERLAY_CLASS = 'feedback-modal-overlay';
53
54const FeedbackModal = ({
55 onRequestClose,
56 initialCategory = FeedbackCategory.BugReport,
57 initialDescription = '',
58 ...props
59}: FeedbackModalProps): ReactElement => {
60 const { displayToast } = useToastNotification();
61 const { themeMode } = useSettingsContext();
62 const fileInputRef = useRef<HTMLInputElement>(null);
63 const hasSubmitted = useRef(false);
64
65 const [category, setCategory] = useState<FeedbackCategory>(initialCategory);
66 const [description, setDescription] = useState(initialDescription);
67 const [screenshot, setScreenshot] = useState<File | null>(null);
68 const [screenshotPreview, setScreenshotPreview] = useState<string | null>(
69 null,
70 );
71 const [isCapturing, setIsCapturing] = useState(false);
72 const [isCropping, setIsCropping] = useState(false);
73
74 // Clean up preview URL when component unmounts or screenshot changes
75 useEffect(() => {
76 return () => {
77 if (screenshotPreview) {
78 revokePreviewUrl(screenshotPreview);
79 }
80 };
81 }, [screenshotPreview]);
82
83 // Validate the incoming file BEFORE revoking the current preview URL, so
84 // a rejected replacement (or an oversized crop result) leaves the existing
85 // attachment and its preview intact.
86 const handleScreenshotChange = useCallback(
87 (file: File | null) => {
88 if (file && !isValidImageType(file)) {
89 displayToast('Invalid image type. Use PNG, JPG, WebP, or GIF.');
90 return;
91 }
92
93 if (file && !isValidFileSize(file)) {
94 displayToast(
95 `File too large. Maximum size is ${
96 MAX_SCREENSHOT_SIZE / 1024 / 1024
97 }MB.`,
98 );
99 return;
100 }
101
102 if (screenshotPreview) {
103 revokePreviewUrl(screenshotPreview);
104 }
105
106 setIsCropping(false);
107 setScreenshot(file);
108 setScreenshotPreview(file ? createPreviewUrl(file) : null);
109 },
110 [screenshotPreview, displayToast],
111 );

Callers

nothing calls this directly

Calls 14

useToastNotificationFunction · 0.90
useSettingsContextFunction · 0.90
revokePreviewUrlFunction · 0.90
isValidImageTypeFunction · 0.90
isValidFileSizeFunction · 0.90
createPreviewUrlFunction · 0.90
captureScreenshotFunction · 0.90
cropImageFileFunction · 0.90
submitFeedbackFunction · 0.90
uploadContentImageFunction · 0.90
useEventListenerFunction · 0.90

Tested by

no test coverage detected