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

Function FeedbackModal

packages/shared/src/components/modals/FeedbackModal.tsx:48–408  ·  view source on GitHub ↗
({
  onRequestClose,
  ...props
}: FeedbackModalProps)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

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
displayToastFunction · 0.85
onRequestCloseFunction · 0.50

Tested by

no test coverage detected