Commit b4c6dee6 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Se agrega la validación de los ids de las categorias y que se registre en el formulario

parent 366353ff
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -57,6 +57,20 @@ const resolver: Resolver<Place> = async (data) => {
    };
  }

  if(!data.categoriesId){
    errors.categoriesId = {
      type: "required",
      message: "Debe seleccionar al menos una categoría"
    }
  }else{
    if(data.categoriesId.length < 1){
      errors.categoriesId = {
        type: "required",
        message: "Debe seleccionar al menos una categoría"
      }
    }
  }

  for(var index = languaguesList.length-1; index>=0; index--){
    if(!data.descriptions || !data.descriptions[index]){
      errors.descriptions = {
@@ -137,6 +151,13 @@ setIsWindowActive?: Dispatch<SetStateAction<boolean>>) => {
  const [placeList, setPlaceList] = useState<Place[]>([]);
  const [isLoading, setIsLoading] = useState(false);
  const [pending, setPending] = useState(false);
  const [categoriesId, setCategoriesId] = useState<number[]>([]);


  useEffect(()=> {
    const categoriesIdString = categoriesId.join(',');
    setValue('categoriesId',categoriesIdString,{shouldValidate: true});
  },[categoriesId]);
  
  useEffect(() => {
    setIsLoading(true);
@@ -228,6 +249,8 @@ setIsWindowActive?: Dispatch<SetStateAction<boolean>>) => {
    resetField,
    updatePlacesByTown,
    placeList,
    pending
    pending,
    categoriesId,
    setCategoriesId,
  };
}