-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement location field for non postal congs
- Loading branch information
Showing
8 changed files
with
164 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import NiceModal, { useModal, bootstrapDialog } from "@ebay/nice-modal-react"; | ||
import { useRollbar } from "@rollbar/react"; | ||
import { set, ref } from "firebase/database"; | ||
import { useState, FormEvent } from "react"; | ||
import { Modal, Form } from "react-bootstrap"; | ||
import { database } from "../../firebase"; | ||
import { USER_ACCESS_LEVELS, WIKI_CATEGORIES } from "../../utils/constants"; | ||
import pollingVoidFunction from "../../utils/helpers/pollingvoid"; | ||
import errorHandler from "../../utils/helpers/errorhandler"; | ||
import ModalFooter from "../form/footer"; | ||
import GenericInputField from "../form/input"; | ||
import HelpButton from "../navigation/help"; | ||
import { ChangeAddressLocationModalProps } from "../../utils/interface"; | ||
|
||
const ChangeAddressLocation = NiceModal.create( | ||
({ | ||
footerSaveAcl = USER_ACCESS_LEVELS.READ_ONLY.CODE, | ||
postalCode, | ||
congregation, | ||
location | ||
}: ChangeAddressLocationModalProps) => { | ||
const [addressLocation, setAddressLocation] = useState(location); | ||
const [isSaving, setIsSaving] = useState(false); | ||
const modal = useModal(); | ||
const rollbar = useRollbar(); | ||
|
||
const handleUpdateBlockName = async (event: FormEvent<HTMLElement>) => { | ||
event.preventDefault(); | ||
setIsSaving(true); | ||
try { | ||
await pollingVoidFunction(() => | ||
set( | ||
ref(database, `addresses/${congregation}/${postalCode}/location`), | ||
addressLocation | ||
) | ||
); | ||
modal.hide(); | ||
} catch (error) { | ||
errorHandler(error, rollbar); | ||
} finally { | ||
setIsSaving(false); | ||
} | ||
}; | ||
return ( | ||
<Modal {...bootstrapDialog(modal)}> | ||
<Modal.Header> | ||
<Modal.Title>Change Location</Modal.Title> | ||
<HelpButton link={WIKI_CATEGORIES.CHANGE_ADDRESS_NAME} /> | ||
</Modal.Header> | ||
<Form onSubmit={handleUpdateBlockName}> | ||
<Modal.Body> | ||
<GenericInputField | ||
label="Location" | ||
name="location" | ||
handleChange={(event) => { | ||
const { value } = event.target as HTMLInputElement; | ||
setAddressLocation(value); | ||
}} | ||
changeValue={addressLocation} | ||
required={true} | ||
/> | ||
</Modal.Body> | ||
<ModalFooter | ||
handleClick={modal.hide} | ||
userAccessLevel={footerSaveAcl} | ||
isSaving={isSaving} | ||
/> | ||
</Form> | ||
</Modal> | ||
); | ||
} | ||
); | ||
|
||
export default ChangeAddressLocation; |
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
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