- {/* biome-ignore lint/performance/noImgElement: uploaded icon is data URL; Next/Image not used for preview */}
+ {/* biome-ignore lint/performance/noImgElement: icon is data URL */}
{
await utils.application.one.invalidate({
applicationId,
});
- } catch (error) {
+ } catch (_error) {
toast.error("Error removing icon");
}
}}
@@ -118,26 +138,23 @@ export const ShowIconSettings = ({ applicationId }: ShowIconSettingsProps) => {
) : (
<>
- {displayedIcons.map((iconName) => (
+ {displayedIcons.map((icon) => (
))}
@@ -146,13 +163,9 @@ export const ShowIconSettings = ({ applicationId }: ShowIconSettingsProps) => {
)}
@@ -173,41 +186,52 @@ export const ShowIconSettings = ({ applicationId }: ShowIconSettingsProps) => {
const file = files[0];
if (!file) return;
- const fileToProcess: File = file;
-
const allowedTypes = [
"image/jpeg",
"image/jpg",
"image/png",
"image/svg+xml",
];
- const fileExtension = fileToProcess.name
- .split(".")
- .pop()
- ?.toLowerCase();
- const allowedExtensions = [
- "jpg",
- "jpeg",
- "png",
- "svg",
- ];
+ const fileExtension = file.name.split(".").pop()?.toLowerCase();
+ const allowedExtensions = ["jpg", "jpeg", "png", "svg"];
if (
- !allowedTypes.includes(fileToProcess.type) &&
- !allowedExtensions.includes(
- fileExtension || "",
- )
+ !allowedTypes.includes(file.type) &&
+ !allowedExtensions.includes(fileExtension || "")
) {
- toast.error(
- "Only JPG, JPEG, PNG, and SVG files are allowed",
- );
+ toast.error("Only JPG, JPEG, PNG, and SVG files are allowed");
return;
}
- if (fileToProcess.size > 2 * 1024 * 1024) {
- toast.error(
- "Image size must be less than 2MB",
- );
+ if (file.size > 2 * 1024 * 1024) {
+ toast.error("Image size must be less than 2MB");
+ return;
+ }
+
+ const isSvg =
+ file.type === "image/svg+xml" || fileExtension === "svg";
+
+ if (isSvg) {
+ const text = await file.text();
+ const sanitizedDataUrl = sanitizeSvg(text);
+ if (!sanitizedDataUrl) {
+ toast.error("Invalid SVG file");
+ return;
+ }
+ setUploadedIcon(sanitizedDataUrl);
+ try {
+ await updateApplication({
+ applicationId,
+ icon: sanitizedDataUrl,
+ });
+ toast.success("Icon saved!");
+ await utils.application.one.invalidate({
+ applicationId,
+ });
+ } catch (_error) {
+ toast.error("Error saving icon");
+ setUploadedIcon(null);
+ }
return;
}
@@ -224,12 +248,12 @@ export const ShowIconSettings = ({ applicationId }: ShowIconSettingsProps) => {
await utils.application.one.invalidate({
applicationId,
});
- } catch (error) {
+ } catch (_error) {
toast.error("Error saving icon");
setUploadedIcon(null);
}
};
- reader.readAsDataURL(fileToProcess);
+ reader.readAsDataURL(file);
}}
classNameWrapper="border-2 border-dashed border-border hover:border-primary bg-muted/30 hover:bg-muted/50 transition-all rounded-lg"
/>
@@ -238,33 +262,6 @@ export const ShowIconSettings = ({ applicationId }: ShowIconSettingsProps) => {
Supported formats: JPG, JPEG, PNG, SVG (max 2MB)