-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: useFeedback hook implementation, used Outlet instead of props
- Loading branch information
1 parent
5c552d5
commit 604c1c1
Showing
8 changed files
with
102 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,32 @@ | ||
import PropTypes from "prop-types"; | ||
|
||
import { Header } from "./Header"; | ||
import { Feedback } from "./Feedback"; | ||
import { useFeedback } from "../hooks/useFeedback"; | ||
|
||
import { useState } from "react"; | ||
import { Outlet } from "react-router-dom"; | ||
|
||
import ToastContainer from "react-bootstrap/ToastContainer"; | ||
|
||
export const Page = ({ MainComponent }) => { | ||
const [feedbackVisible, setFeedbackVisible] = useState(false); | ||
const [feedback, setFeedback] = useState([]); | ||
|
||
const setupFeedback = (reportedFeedback) => { | ||
setFeedback(reportedFeedback); | ||
setFeedbackVisible(true); | ||
}; | ||
export const Page = () => { | ||
const { feedback, showFeedback, toggleFeedback } = useFeedback(); | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<MainComponent triggerFeedback={setupFeedback} /> | ||
<Outlet /> | ||
<ToastContainer position="top-end" className="m-4"> | ||
{feedbackVisible && | ||
{showFeedback && | ||
feedback.map((feedbackItem, i) => { | ||
return ( | ||
<Feedback | ||
key={i} | ||
title={feedbackItem.title} | ||
message={feedbackItem.message} | ||
type={feedbackItem.type} | ||
toggleVisible={() => setFeedbackVisible(!feedbackVisible)} | ||
toggleVisible={toggleFeedback} | ||
/> | ||
); | ||
})} | ||
</ToastContainer> | ||
</> | ||
); | ||
}; | ||
|
||
Page.propTypes = { | ||
MainComponent: PropTypes.elementType.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters