X Access Token Bearer
X Access Token Bearer
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlRzWEo0MFFXZHlwSG9mUnNVLUpFWiJ9.eyJodH
RwczovL2FwaS1sb3RvYm9sYS1wZS1kZXZlbG9wbWVudC9jbGFpbXMvYXBwX21ldGFkYXRhLyI6e30sImh0d
HBzOi8vYXBpLWxvdG9ib2xhLXBlLWRldmVsb3BtZW50L2NsYWltcy91c2VyX25hbWUvIjoiYWxlamFuZHJv
QGVsb3Rncm91cC5jb20iLCJpc3MiOiJodHRwczovL2xvdG9ib2xhLXBlLWRldmVsb3BtZW50LmV1LmF1dGg
wLmNvbS8iLCJzdWIiOiJhdXRoMHw2NzY1YmE2OWRlMTk2ZmZjNjE0ODFiMzgiLCJhdWQiOlsiaHR0cHM6Ly
9hcGktbG90b2JvbGEtcGUtZGV2ZWxvcG1lbnQiLCJodHRwczovL2xvdG9ib2xhLXBlLWRldmVsb3BtZW50L
mV1LmF1dGgwLmNvbS91c2VyaW5mbyJdLCJpYXQiOjE3MzY5NTU3NjgsImV4cCI6MTczNzA0MjE2OCwic2Nv
cGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCIsImF6cCI6IlFSbWxSZ0tuMHdFTU5GdVpCS1NXZVJNakJweTI
5WGFwIn0.p0GZfv0zM7vQvImBVzi7ddoXs-yPWSXP6e5TyGIUP-IwIPhAG6aS5uXtMF-
jCF0sMku5t2GYUb0wi3kU807G745Lq-05OIaQgkDydsb-f7_ziq44EZeZ5L-
o60ZXlHqMb92kfz4TEGmg3VyKonISRavwVO_boSutdK4Sb0o4MXiUB9OmpKgKwbl0ZoS-
yXhBDPLExAv8QGuJYWI6cTMkjZY3EiwSAvY3FUaBEbu2gfGAtfNYNpA0yXq0pVpUEI9yEkvTj6JtmpoWZB1
JOxvpwNoZtjDYYWUsicjCVLm-FE0cENHfWrmjoQYzffQEFej2mt12H8CAulSmL2mYpqXVpg
<input
name="imageHeroBanner"
accept="image/*"
className="hidden"
id="button-file"
type="file"
onChange={async (e) => {
const file =
e.target.files?.[0];
if (file) {
const uploadedImageUrl
= await readFileAsync(file);
if
(methods.getValues('deviceType') === 'desktop') {
setUploadedImageUrlHeroDesktop(uploadedImageUrl);
} else {
setUploadedImageUrlHeroMobile(uploadedImageUrl);
}
}
}}
/>
// if (!currentTheme) {
// currentTheme = {
// lotteryId,
// desktop: {
// heroBanner: {
// src: '',
// title: '',
// },
// detailsImage: {
// src: '',
// title: '',
// },
// },
// mobile: {
// heroBanner: {
// src: '',
// title: '',
// },
// detailsImage: {
// src: '',
// title: '',
// },
// },
// };
La razón por la que se hace esto es asegurarse de que currentTheme siempre tenga un
valor válido, especialmente cuando más adelante se espera manipularlo o utilizarlo
dentro de un array (lotteriesThemesList). Si currentTheme no está inicializado
correctamente, se pueden generar errores al intentar acceder a sus propiedades más
adelante.
En resumen:
<Button
variant="outlined"
component="label"
sx={{
mt: 2,
borderRadius: '5px',
border: 'none',
backgroundColor: '#f5f5f5',
pt: (
uploadedImageUrlDetailsDesktop && {
width: '100%',
height: '100%',
}),
...
(methods.getValues('deviceType') === 'mobile' &&
uploadedImageUrlDetailsMobile && {
width: '100%',
height: '100%',
}),
}}
>
{(
methods.getValues('deviceType')
=== 'desktop'
?
uploadedImageUrlDetailsDesktop
:
uploadedImageUrlDetailsMobile
) ? (
<img
src={
setUploadedImageUrlDetailsDesktop(uploadedImageUrl);
} else {
setUploadedImageUrlDetailsMobile(uploadedImageUrl);
}
}
}}
/>
</Button>
setCurrentTheme({
...theme,
desktop: {
heroBanner: normalizeImage(theme.desktop?.heroBanner),
detailsImage: normalizeImage(theme.desktop?.detailsImage),
},
mobile: {
heroBanner: normalizeImage(theme.mobile?.heroBanner),
detailsImage: normalizeImage(theme.mobile?.detailsImage),
},
});
const updateImageState = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setImage: React.Dispatch<React.SetStateAction<any>>,
src: string | null,
formValue: string | null
) => {
const finalSrc = formValue || src; // Priorizar el valor del formulario
si está definido
setImage(finalSrc ? {url: finalSrc, base64: '', fileName: 'filename',
data: '', mimeType: ''} : null);
};
type LotteryIdSelectProps = {
lotteryId?: string;
setToastMessage?: (message: string) => void;
onLotteryIdChange: (lotteryId: string) => void;
};
useEffect(() => {
if (lotteryId) {
setValue('lotteryId', lotteryId);
}
}, [lotteryId, setValue]);
return (
<Controller
control={control}
name="lotteryId"
render={({field}) => (
<>
<Select {...field} labelId="lottery-select-label" displayEmpty
className="w-[400px] mb-[54px]">
{lotteryId && <MenuItem
value={lotteryId}>{lotteryId}</MenuItem>}
</Select>
</>
)}
/>
);
}
<LotteryIdSelect
lotteryId={lotteryId}
onLotteryIdChange={(selectedLotteryId) => {
console.log('LotteryId seleccionado:',
selectedLotteryId);
methods.setValue('lotteryId',
selectedLotteryId);
setLotteryId(selectedLotteryId);
}}
/>
useEffect(() => {
const newLotteryId = uuid();
console.log('Nuevo lotteryId generado:', newLotteryId);
setLotteryId(newLotteryId);
setTimeout(() => {
methods.setValue('lotteryId', newLotteryId);
}, 0);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++
onsuccess:
queryClient.setQueryData(['lotteryTheme'], (oldData: any) => {
if (!oldData) return oldData;
const updatedValue = JSON.parse(data.configuration.value) as
ILotteryThemeDatum[];
return { ...oldData, configuration: { ...oldData.configuration, value:
JSON.stringify(updatedValue) } };
});
try {
await createThemeMutation(payload);
setToastMessage(t('updatedSuccessfully'));
setIsSaved(true);
} catch (error) {
setToastMessage(t('failedTheme'));
}
};
methods.clearErrors('themeJSON');
}
// Validar el JSON
inicial
const validationError = validateJSONInput(jsonString);
setIsJSONValid(!validationError);
if (validationError) {
methods.setError('themeJSON', {
type: 'manual',
message: validationError,
});
} else {
methods.clearErrors('themeJSON');
}
// Revalidar formulario
methods.trigger('themeJSON');
useEffect(() => {
if (lotteryThemes && lotteryId) {
const theme = lotteryThemes.find((t) => t.lotteryId === lotteryId);
if (theme) {
const {name, lotteryId, configurationName, ...filteredTheme} =
theme;
//const jsonString = JSON.stringify(filteredTheme, null, 2);
methods.setValue('themeJSON', filteredTheme);
methods.setValue('lotteryId', lotteryId);
setIsJSONValid(!validationError);
if (validationError) {
methods.setError('themeJSON', {
type: 'manual',
message: validationError,
});
} else {
methods.clearErrors('themeJSON');
}
// Revalidar formulario
methods.trigger('themeJSON');
}
}
}, [lotteryId, lotteryThemes, methods]);