11import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema" ;
2- import DOMPurify from "dompurify" ;
2+
33import { GlobeIcon , PenBoxIcon , Plus , X } from "lucide-react" ;
4- import { useEffect , useState , useRef } from "react" ;
4+ import { useEffect , useRef , useState } from "react" ;
55import { useForm } from "react-hook-form" ;
66import { toast } from "sonner" ;
77import { z } from "zod" ;
@@ -26,6 +26,7 @@ import {
2626} from "@/components/ui/form" ;
2727import { Input } from "@/components/ui/input" ;
2828import { api } from "@/utils/api" ;
29+ import { sanitizeSvg } from "@/utils/sanitize-svg" ;
2930
3031const organizationSchema = z . object ( {
3132 name : z . string ( ) . min ( 1 , {
@@ -43,20 +44,6 @@ interface Props {
4344 onOpenChange ?: ( open : boolean ) => void ;
4445}
4546
46- const sanitizeSvg = ( svgContent : string ) : string | null => {
47- const clean = DOMPurify . sanitize ( svgContent , {
48- USE_PROFILES : { svg : true , svgFilters : true } ,
49- ADD_TAGS : [ "use" ] ,
50- } ) ;
51- if ( ! clean ) return null ;
52- const bytes = new TextEncoder ( ) . encode ( clean ) ;
53- let binString = "" ;
54- for ( let i = 0 ; i < bytes . length ; i ++ ) {
55- binString += String . fromCharCode ( bytes [ i ] ! ) ;
56- }
57- return `data:image/svg+xml;base64,${ btoa ( binString ) } ` ;
58- } ;
59-
6047const resizeImage = ( file : File , maxSize : number ) : Promise < string > => {
6148 return new Promise ( ( resolve , reject ) => {
6249 const reader = new FileReader ( ) ;
@@ -106,7 +93,9 @@ export function AddOrganization({
10693 const uploadCounter = useRef ( 0 ) ;
10794 const isControlled = controlledOpen !== undefined ;
10895 const open = isControlled ? controlledOpen : internalOpen ;
109- const setOpen = isControlled ? controlledOnOpenChange ! : setInternalOpen ;
96+ const setOpen = isControlled
97+ ? controlledOnOpenChange || ( ( ) => { } )
98+ : setInternalOpen ;
11099 const utils = api . useUtils ( ) ;
111100 const { data : organization } = api . organization . one . useQuery (
112101 {
0 commit comments