Tenant Creation – Logo removed when navigating back from second page
This commit is contained in:
parent
acb899dd2e
commit
ddfe09b570
@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useFormContext } from "react-hook-form";
|
import { useFormContext } from "react-hook-form";
|
||||||
|
|
||||||
const toBase64 = (file) =>
|
const toBase64 = (file) =>
|
||||||
@ -10,11 +10,15 @@ const toBase64 = (file) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const LogoUpload = ({ preview, setPreview, fileName, setFileName }) => {
|
export const LogoUpload = ({ preview, setPreview, fileName, setFileName }) => {
|
||||||
const {
|
const { register, setValue, watch, formState: { errors } } = useFormContext();
|
||||||
register,
|
const logoImage = watch("logoImage");
|
||||||
setValue,
|
|
||||||
formState: { errors },
|
// Sync preview when the form value changes
|
||||||
} = useFormContext();
|
useEffect(() => {
|
||||||
|
if (logoImage && !preview) {
|
||||||
|
setPreview(logoImage); // Use base64 as preview
|
||||||
|
}
|
||||||
|
}, [logoImage, preview, setPreview]);
|
||||||
|
|
||||||
const handleUpload = async (e) => {
|
const handleUpload = async (e) => {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useFormContext, Controller } from "react-hook-form";
|
import { useFormContext, Controller } from "react-hook-form";
|
||||||
import Label from "../common/Label";
|
import Label from "../common/Label";
|
||||||
import DatePicker from "../common/DatePicker";
|
import DatePicker from "../common/DatePicker";
|
||||||
@ -57,6 +57,13 @@ const OrganizationInfo = ({ onNext, onPrev, onSubmitTenant }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const logoImage = getValues("logoImage");
|
||||||
|
if (logoImage) {
|
||||||
|
setLogoPreview(logoImage);
|
||||||
|
setLogoName("Uploaded Logo");
|
||||||
|
}
|
||||||
|
}, [getValues]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user