-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAddOrganizationModal.jsx
More file actions
86 lines (80 loc) · 2.49 KB
/
Copy pathAddOrganizationModal.jsx
File metadata and controls
86 lines (80 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import PropTypes from "prop-types";
import { Formik } from "formik";
import React from "react";
import BoGButton from "./BoGButton";
import InputField from "./Forms/InputField";
import "flowbite-react";
import { updateUserOrganizationId } from "../queries/users";
import router from "next/router";
import { signOut } from "next-auth/react";
class AddOrganizationModal extends React.Component {
constructor(props) {
super(props);
this.error = false;
this.state = {
prompt: "",
};
}
handleSubmit = async (values) => {
if (this.props.data.user) {
updateUserOrganizationId(this.props.data.user?._id, values.orgCode)
.then((res) => {
if (res.status === 200) {
router.reload();
}
})
.catch(() => {
this.setState({
prompt: "The provided ORG CODE was incorrect. Please try again",
});
});
}
};
render() {
return (
<div className="flex h-screen flex-col items-center justify-center">
<div className="flex h-screen w-1/4 flex-col items-center justify-center">
<h2 className="mb-4 text-2xl font-semibold">Enter Org Code</h2>
<React.Fragment>
<Formik
initialValues={{
orgCode: "",
}}
onSubmit={(values, { setSubmitting }) => {
setSubmitting(true);
this.handleSubmit(values);
setSubmitting(false);
}}
>
{({ handleSubmit, isSubmitting }) => (
<form className="flex-column flex w-full space-y-2">
<div className="flex space-x-4">
<InputField
name="orgCode"
label={this.state.prompt}
className="w-full"
/>
</div>
<BoGButton
className="color-blue"
onClick={handleSubmit}
disabled={isSubmitting}
text="Submit Code"
type="submit"
/>
<button className="mt-8 hover:underline" onClick={signOut}>
Wrong account? Log out
</button>
</form>
)}
</Formik>
</React.Fragment>
</div>
</div>
);
}
}
AddOrganizationModal.propTypes = {
data: PropTypes.object.isRequired,
};
export default AddOrganizationModal;