Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

072 react auto redirect to homepage #105

Merged
merged 4 commits into from
Nov 26, 2023

Conversation

SirrorsMoore1975
Copy link
Contributor

@SirrorsMoore1975 SirrorsMoore1975 commented Nov 25, 2023

What I did:
Main focus on Form.jsx

  • Removed Home Button
  • Created a new component within Form.jsx called <Notice>
  • Add features to auto redirect to home page after 7s:
// unique components for Form.jsx
  const Notice = ({res}) => {
    // Control redirect homepage action at the Thankyou component
    const [timeLeft, setTimeLeft] = useState(7)

    useEffect(()=>{
      // control clicked home button
      const myTimeout = setTimeout(()=>{
          handleRedirect();
        }, Number(timeLeft * 1000);
      
      return () => {
        clearTimeout(myTimeout);
      }  
    }, []);

    useEffect(()=>{
      const timer = timeLeft > 0 && setInterval(()=> {setTimeLeft(timeLeft -1)}, 1000);
      return () => clearInterval(timer)
    },[timeLeft])

    const handleRedirect = () => {
      navigate('/');
    }

    return (
      <div className="thanks">    
            <Header className="header" text="Thank you for your feedback!" secondary_text={res}/>
            <span align="center">{`You will be redirected to Home in ${timeLeft}s`}</span>
            <Footer className="footer" text="© 2023 Phone Carrier Review App"/>
          </div>
    )
    
  }
  • Form.css add color to background and fonts to className="thanks"

@SirrorsMoore1975 SirrorsMoore1975 linked an issue Nov 25, 2023 that may be closed by this pull request
Copy link
Contributor

@LakGillJPN LakGillJPN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the redirect and it works great! The timer is a very nice touch.

@LakGillJPN LakGillJPN merged commit 7d2777b into main Nov 26, 2023
@SirrorsMoore1975 SirrorsMoore1975 deleted the 072-react-auto-redirect-to-homepage branch November 28, 2023 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React: Auto-redirect to Homepage
2 participants