/* eslint-disable import/no-unresolved */


import { useEffect, useState } from "react";

import { useDispatch, useSelector } from "react-redux";

import { getCommandes } from "../features/commande/thunk";


export function useCommande() {
  const dispatch = useDispatch<any>();
  const status = useSelector((state: any) => state.commande.status);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    const load = async () => {
      if (status === "idle") {
        setLoading(true);
        await dispatch(getCommandes()).unwrap();
        setLoading(false);
      }
    };

    load();
  }, [dispatch, status]);

  return { loading, status };
}
