diff --git a/app/account/citizenship/apply/form.tsx b/app/account/citizenship/apply/form.tsx index bc37402..9480521 100644 --- a/app/account/citizenship/apply/form.tsx +++ b/app/account/citizenship/apply/form.tsx @@ -1,6 +1,6 @@ "use client"; -import { useActionState, useEffect, useRef, useState } from "react"; +import { useActionState, useEffect, useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { @@ -30,7 +30,6 @@ import { initialFormState } from "@/lib/form-action"; import { EYE_COLORS } from "@/lib/citizenship/types"; import { Spinner } from "@/components/ui/spinner"; import { ImageUploader } from "@/components/image-uploader"; -import { removeBackground } from "@imgly/background-removal"; type Props = { firstName: string; @@ -51,9 +50,6 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa const [appType, setAppType] = useState(""); const [state, formAction, isPending] = useActionState(submitCitizenshipApplication, initialFormState); const [isEuResident, setIsEuResident] = useState(null); - const [profileProcessing, setProfileProcessing] = useState(false); - const profileInputRef = useRef(null); - const signatureInputRef = useRef(null); useEffect(() => { if (state.error) { @@ -63,37 +59,6 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa const errors = state.fieldErrors ?? {}; - async function handleProfileSelect(file: File) { - setProfileProcessing(true); - try { - const resultBlob = await removeBackground(file); - const processedFile = new File([resultBlob], file.name, { type: "image/png" }); - const dt = new DataTransfer(); - dt.items.add(processedFile); - if (profileInputRef.current) profileInputRef.current.files = dt.files; - } catch { - const dt = new DataTransfer(); - dt.items.add(file); - if (profileInputRef.current) profileInputRef.current.files = dt.files; - } finally { - setProfileProcessing(false); - } - } - - function handleSignatureSelect(file: File) { - const dt = new DataTransfer(); - dt.items.add(file); - if (signatureInputRef.current) signatureInputRef.current.files = dt.files; - } - - function handleProfileRemove() { - if (profileInputRef.current) profileInputRef.current.value = ""; - } - - function handleSignatureRemove() { - if (signatureInputRef.current) signatureInputRef.current.value = ""; - } - return (
@@ -322,26 +287,23 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa Images Provide your profile image and your signature for your identity document. - - diff --git a/components/editor.tsx b/components/editor.tsx index 45991d1..f9a77fc 100644 --- a/components/editor.tsx +++ b/components/editor.tsx @@ -271,7 +271,7 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E }} /> -
+
diff --git a/components/image-uploader.tsx b/components/image-uploader.tsx index c5d2f8a..ee6e346 100644 --- a/components/image-uploader.tsx +++ b/components/image-uploader.tsx @@ -49,6 +49,12 @@ function validateFile(file: File, accept: string): string | null { return null; } +function fileToFileList(file: File): FileList { + const dt = new DataTransfer(); + dt.items.add(file); + return dt.files; +} + export function ImageUploader({ id, name, label, description, error, variant = "default", previewClassName, accept = DEFAULT_ACCEPT, required, value, onFileSelect, onRemove, isUploading, children, caption, onCaptionChange }: Props) { const inputRef = useRef(null); const [previewUrl, setPreviewUrl] = useState(null); @@ -99,7 +105,12 @@ export function ImageUploader({ id, name, label, description, error, variant = " e.preventDefault(); setIsDragOver(false); const file = e.dataTransfer.files?.[0]; - if (file) applyFile(file); + if (!file) return; + + if (inputRef.current) { + inputRef.current.files = fileToFileList(file); + } + applyFile(file); } const displayedError = clientError ?? error; @@ -167,11 +178,17 @@ export function ImageUploader({ id, name, label, description, error, variant = " {label} -
+
{ e.preventDefault(); setIsDragOver(true); }} + onDragLeave={() => setIsDragOver(false)} + onDrop={handleDrop} + className="flex flex-col md:flex-row items-start gap-4" + >
{isUploading ? ( diff --git a/lib/user/actions.ts b/lib/user/actions.ts index 72d59ea..73dddc4 100644 --- a/lib/user/actions.ts +++ b/lib/user/actions.ts @@ -30,7 +30,6 @@ export async function login() { state, }); - //Frontend public url, not api. And wtf I need to dubplicate it all redirect(`${process.env.KOTOSOFT_ID_API_PUBLIC_URL}/oauth/authorize?${params}`); }