导航表演越野车

问题描述 投票:0回答:0

我有一个奇怪的场景,如果用户不满足条件,就会被导航到入职页面。完成并尝试发送表单后,它不会导航到主页,而只是停留在入职页面上。我可以看到业务已在我的 ORM 中创建,但由于某种原因,用户仍停留在入职页面上。请问我做错了什么?

Onboarding.jsx

const Onboarding = () => {

  const navigate = useNavigate();
  const dispatch = useDispatch();

  const { message, isError, isSuccess, isLoading } = useSelector(
    (state) => state.organization
  );

  useEffect(() => {
    if (isError) {
      toast({
        title: "Error",
        description: message,
        status: "error",
        position: "top-right",
        duration: 5000,
        isClosable: true,
      });
    }

    if (isSuccess) {
      toast({
        title: "Congrats!🎉",
        description: "Onboarding completed.",
        status: "success",
        position: "top-right",
        duration: 5000,
        isClosable: true,
      });
      navigate("/");
    }

    dispatch(reset());
  }, [navigate, dispatch, isSuccess, isError, message]);

  const toast = useToast()

  const [step, setStep] = useState(0);

  const steps = ["", "", "",];

  const [formData, setFormData] = useState({
    businessName: "",
    businessEmail: "",
    currency: "",
    industry: "",
    businessDescription: "",
    useCase: "",
    organisationType: "",
    website: "",
    businessPhone: "",
    country: "",
    billingName: "",
    billingEmail: "",
    addressState: "",
    addressCity: "",
    addressStreet: ""
  });

  const { businessName, businessEmail, currency, industry, businessDescription, useCase, organisationType, website, businessPhone, country, billingName, billingEmail, addressCity, addressState, addressStreet } =
    formData;

  const handleSubmit = () => {
    if (step === 0) {
      if (formData.businessName === '') {
        toast({
          title: 'Error',
          description: ('Please provide a business name'),
          status: 'error',
         position: 'top-right',
          duration: 3000,
          isClosable: true,
        })
      } else {
        setStep(step + 1);
      }

    } else if (step === 1) {
      if (formData.website === '') {
        toast({
          title: 'Error',
          description: ('Please provide a website'),
          status: 'error',
         position: 'top-right',
          duration: 3000,
          isClosable: true,
        })
      } else {
        setStep(step + 1);
      }
    } else if (step === 2) {
      if (formData.billingName === '') {
        toast({
          title: 'Error',
          description: ('Please provide a billing name'),
          status: 'error',
         position: 'top-right',
          duration: 3000,
          isClosable: true,
        })
      } else {
        const formData = {
          businessName,
          businessEmail,
          currency,
          industry,
          businessDescription,
          useCase,
          organisationType,
          website,
          businessPhone,
          country,
          billingName,
          billingEmail,
          addressCity,
          addressState,
          addressStreet
        };
        dispatch(createOrganization(formData))
      }
    } 
  };

这是处理路由的函数

const { message } = useSelector(
  (state) => state.auth
);

const navigate = useNavigate()

useEffect(() => {
  if (message=== "This user does not have a business account, please create one and continue.") {
    navigate("/auth/onboarding");
  }
}, [message])
javascript reactjs redux router
© www.soinside.com 2019 - 2024. All rights reserved.