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

preserving form content on refresh #335

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/components/dashboard/AddProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,26 @@ function AddProvider(props) {
const [descriptions, setDescriptions] = useState(null);
const [single, setSingle] = useState(null);
const [error, setError] = useState("");
const [firstLoad, setFirstLoad] = useState(true);
const [content, setContent] = useState(
'ex. "Changing lives one bit at a time..."'
);
const handleUpdate = (updatedContent: string) => {
setContent(updatedContent);
};

useEffect(() => {
console.log((sessionStorage.getItem("item")))
if (firstLoad === false) {
sessionStorage.setItem('item', JSON.stringify(item))
} else {
if(JSON.parse(sessionStorage.getItem("item")) !== null) {
setItem(JSON.parse(sessionStorage.getItem("item")))
}
setFirstLoad(false)
}
}, [item])

useEffect(() => {
async function fetchData() {
const collections = props.firestore.collection("categories");
Expand Down Expand Up @@ -195,6 +208,7 @@ function AddProvider(props) {
};

async function addFirestore() {
sessionStorage.clear()
setIsLoading(true);
const i = {
...item,
Expand Down Expand Up @@ -256,6 +270,7 @@ function AddProvider(props) {
}

async function updateFirestore() {
sessionStorage.clear()
setIsLoading(true);
const i = {
...item,
Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/RowForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const RowForm = (props) => {
};

const [item, setItem] = useState(
props.item.facilityName ? props.item : defaultItem
props.item.facilityName ? props.item : JSON.parse(sessionStorage.getItem("item")) || defaultItem
);
const [showModal, setShowModal] = useState(false);

Expand Down
1 change: 1 addition & 0 deletions src/components/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function Dashboard({ firestore, team, selectItem }) {
}
}
fetchData()
sessionStorage.clear()
setIsLoading(false);
}, [team, isLoading]);

Expand Down