diff --git a/apps/client/src/pages/builder/sidebars/left/dialogs/profiles.tsx b/apps/client/src/pages/builder/sidebars/left/dialogs/profiles.tsx index 71811b2a..d1ff051e 100644 --- a/apps/client/src/pages/builder/sidebars/left/dialogs/profiles.tsx +++ b/apps/client/src/pages/builder/sidebars/left/dialogs/profiles.tsx @@ -12,11 +12,13 @@ import { FormMessage, Input, } from "@reactive-resume/ui"; -import { useForm } from "react-hook-form"; +import { ControllerRenderProps, useForm } from "react-hook-form"; import { z } from "zod"; import { SectionDialog } from "../sections/shared/section-dialog"; import { URLInput } from "../sections/shared/url-input"; +import { useDebounceValue } from "usehooks-ts"; +import { useCallback } from "react"; const formSchema = profileSchema; @@ -28,6 +30,29 @@ export const ProfilesDialog = () => { resolver: zodResolver(formSchema), }); + const [iconSrc, setIconSrc] = useDebounceValue("", 400) + + const handleIconChange = useCallback((event: React.ChangeEvent, field: ControllerRenderProps<{ + id: string; + visible: boolean; + network: string; + username: string; + icon: string; + url: { + label: string; + href: string; + }; + }, "icon">) => { + field.onChange(event); + if (event.target.value === "") { + setIconSrc(""); + } else { + setIconSrc(`https://cdn.simpleicons.org/${event.target.value}`); + } + }, []); + + + return ( id="profiles" form={form} defaultValues={defaultProfile}>
@@ -83,14 +108,14 @@ export const ProfilesDialog = () => {
- {field.value && ( + {iconSrc && ( )} - + handleIconChange(e, field)} />