Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InviteDialog.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import React from "react";
  2. import planeVector from "../../assets/images/planeVector.png";
  3. import * as Yup from "yup";
  4. import PropTypes from "prop-types";
  5. import {
  6. Dialog,
  7. DialogContent,
  8. DialogTitle,
  9. DialogActions,
  10. useMediaQuery,
  11. useTheme,
  12. IconButton,
  13. TextField,
  14. } from "@mui/material";
  15. import { useDispatch, useSelector } from "react-redux";
  16. import { useEffect } from "react";
  17. import { inviteUserReq } from "../../store/actions/users/usersActions";
  18. import { useTranslation } from "react-i18next";
  19. import { useFormik } from "formik";
  20. const InviteDialog = ({
  21. title,
  22. onClose,
  23. open,
  24. maxWidth,
  25. fullWidth,
  26. responsive,
  27. }) => {
  28. const dispatch = useDispatch();
  29. const { isSuccess } = useSelector((s) => s.invite);
  30. const theme = useTheme();
  31. const fullScreen = useMediaQuery(theme.breakpoints.down("md"));
  32. const { t } = useTranslation();
  33. const handleClose = () => {
  34. onClose();
  35. formik.resetForm();
  36. };
  37. const handleSubmit = (values, { resetForm }) => {
  38. const { lastName, firstName, email } = values;
  39. dispatch(
  40. inviteUserReq({
  41. invite: {
  42. lastName,
  43. firstName,
  44. email,
  45. },
  46. handleApiResponseSuccess: resetForm,
  47. })
  48. );
  49. };
  50. const formik = useFormik({
  51. initialValues: {
  52. firstName: "",
  53. lastName: "",
  54. email: "",
  55. },
  56. validationSchema: Yup.object().shape({
  57. firstName: Yup.string().required(t("login.firstnameRequired")),
  58. lastName: Yup.string().required(t("login.lastnameRequired")),
  59. email: Yup.string()
  60. .required(t("login.emailRequired"))
  61. .matches(/^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/, t("login.invalidEmail")),
  62. }),
  63. onSubmit: handleSubmit,
  64. validateOnBlur: true,
  65. enableReinitialize: true,
  66. });
  67. useEffect(() => {
  68. handleClose();
  69. }, [dispatch, isSuccess]);
  70. return (
  71. <Dialog
  72. maxWidth={maxWidth}
  73. fullWidth={fullWidth}
  74. fullScreen={responsive && fullScreen}
  75. onClose={handleClose}
  76. open={open}
  77. style={{
  78. padding: "36px",
  79. }}
  80. >
  81. <div style={{ padding: "36px" }} data-testid="invite-dialog-container">
  82. <DialogTitle style={{ padding: 0 }} data-testid="invite-title">
  83. {title}
  84. </DialogTitle>
  85. <DialogContent style={{ padding: "50px 0px 10px 0px" }}>
  86. <form onSubmit={formik.handleSubmit} data-testid="invite-form">
  87. {/* <label>Primaoc</label> */}
  88. <div
  89. className=""
  90. style={{
  91. display: fullScreen ? "" : "flex",
  92. justifyContent: "center",
  93. alignItems: "start",
  94. gap: "15px",
  95. }}
  96. >
  97. <TextField
  98. // correct way to set test id on mui textfield
  99. inputProps={{ "data-testid": "invite-input-text" }}
  100. name="firstName"
  101. // label={t("users.receiver")}
  102. label={t("common.firstName")}
  103. margin="normal"
  104. value={formik.values.firstName}
  105. onChange={formik.handleChange}
  106. error={
  107. formik.touched.firstName && Boolean(formik.errors.firstName)
  108. }
  109. helperText={formik.touched.firstName && formik.errors.firstName}
  110. fullWidth
  111. />
  112. <TextField
  113. inputProps={{ "data-testid": "invite-input-text" }}
  114. name="lastName"
  115. // label={t("users.receiver")}
  116. label={t("common.lastName")}
  117. margin="normal"
  118. value={formik.values.lastName}
  119. onChange={formik.handleChange}
  120. error={
  121. formik.touched.lastName && Boolean(formik.errors.lastName)
  122. }
  123. helperText={formik.touched.lastName && formik.errors.lastName}
  124. fullWidth
  125. />
  126. </div>
  127. <TextField
  128. inputProps={{ "data-testid": "invite-input-text" }}
  129. name="email"
  130. // label={t("users.receiver")}
  131. label={"E-mail " + t("common.address")}
  132. margin="normal"
  133. value={formik.values.email}
  134. onChange={formik.handleChange}
  135. error={formik.touched.email && Boolean(formik.errors.email)}
  136. helperText={formik.touched.email && formik.errors.email}
  137. fullWidth
  138. />
  139. <IconButton
  140. className={"c-btn--primary c-btn inviteBtn"}
  141. data-testid="invite-btn"
  142. sx={{
  143. width: "100%",
  144. marginTop: "15px",
  145. }}
  146. type="submit"
  147. >
  148. <img
  149. style={{
  150. position: "relative",
  151. top: 1.25,
  152. paddingRight: "15px",
  153. }}
  154. src={planeVector}
  155. />{" "}
  156. {t("registration.link")}
  157. </IconButton>
  158. </form>
  159. </DialogContent>
  160. <DialogActions style={{ padding: 0 }}></DialogActions>
  161. </div>
  162. </Dialog>
  163. );
  164. };
  165. InviteDialog.propTypes = {
  166. title: PropTypes.any,
  167. open: PropTypes.bool.isRequired,
  168. onClose: PropTypes.func.isRequired,
  169. maxWidth: PropTypes.oneOf(["xs", "sm", "md", "lg", "xl"]),
  170. fullWidth: PropTypes.bool,
  171. responsive: PropTypes.bool,
  172. };
  173. export default InviteDialog;