ProactiveQuestionnaireModal.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { useState, useCallback } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import {
  4. Modal, ModalBody,
  5. } from 'reactstrap';
  6. import { apiv3Post } from '~/client/util/apiv3-client';
  7. type ModalProps = {
  8. isOpen: boolean,
  9. onClose: () => void,
  10. };
  11. const QuestionnaireCompletionModal = (props: ModalProps): JSX.Element => {
  12. const { t } = useTranslation('commons');
  13. const { isOpen, onClose } = props;
  14. return (
  15. <Modal
  16. size="lg"
  17. isOpen={isOpen}
  18. toggle={onClose}
  19. centered
  20. >
  21. <ModalBody className="bg-primary overflow-hidden p-0" style={{ borderRadius: 8 }}>
  22. <div className="bg-white m-2 p-4" style={{ borderRadius: 8 }}>
  23. <div className="text-center">
  24. <h2 className="my-4">{t('questionnaire_modal.title')}</h2>
  25. <p className="mb-1">{t('questionnaire_modal.successfully_submitted')}</p>
  26. <p>{t('questionnaire_modal.thanks_for_answering')}</p>
  27. </div>
  28. <div className="text-center my-3">
  29. <span style={{ cursor: 'pointer', textDecoration: 'underline' }} onClick={onClose}>{t('Close')}</span>
  30. </div>
  31. </div>
  32. </ModalBody>
  33. </Modal>
  34. );
  35. };
  36. const ProactiveQuestionnaireModal = (props: ModalProps): JSX.Element => {
  37. const { t } = useTranslation('commons');
  38. const { isOpen, onClose } = props;
  39. const [isQuestionnaireCompletionModal, setQuestionnaireCompletionModal] = useState(false);
  40. const submitHandler = useCallback(async(e) => {
  41. e.preventDefault();
  42. const formData = e.target.elements;
  43. const {
  44. satisfaction: { value: satisfaction },
  45. lengthOfExperience: { value: lengthOfExperience },
  46. occupation: { value: occupation },
  47. position: { value: position },
  48. commentText: { value: commentText },
  49. } = formData;
  50. const sendValues = {
  51. satisfaction: Number(satisfaction),
  52. lengthOfExperience,
  53. occupation,
  54. position,
  55. commentText,
  56. };
  57. apiv3Post('/questionnaire/proactive/answer', sendValues);
  58. onClose();
  59. setQuestionnaireCompletionModal(true);
  60. }, [onClose]);
  61. return (
  62. <>
  63. <Modal
  64. data-testid="grw-proactive-questionnaire-modal"
  65. size="lg"
  66. isOpen={isOpen}
  67. toggle={onClose}
  68. centered
  69. >
  70. <ModalBody className="bg-primary overflow-hidden p-0" style={{ borderRadius: 8 }}>
  71. <div className="bg-white m-2 p-4" style={{ borderRadius: 8 }}>
  72. <div className="text-center">
  73. <h2 className="my-4">{t('questionnaire_modal.title')}</h2>
  74. <p className="mb-1">{t('questionnaire_modal.more_satisfied_services')}</p>
  75. <p>{t('questionnaire_modal.strive_to_improve_services')}</p>
  76. </div>
  77. <form className="px-5" onSubmit={submitHandler}>
  78. <div className="form-group row mt-5">
  79. <label className="col-sm-5 col-form-label" htmlFor="satisfaction">
  80. <span className="badge badge-primary mr-2">{t('questionnaire_modal.required')}</span>{t('questionnaire_modal.satisfaction_with_growi')}
  81. </label>
  82. <select className="col-sm-7 form-control" name="satisfaction" id="satisfaction" required>
  83. <option value="">▼ {t('Select')}</option>
  84. <option>1</option>
  85. <option>2</option>
  86. <option>3</option>
  87. <option>4</option>
  88. <option>5</option>
  89. </select>
  90. </div>
  91. <div className="form-group row mt-3">
  92. <label className="col-sm-5 col-form-label" htmlFor="lengthOfExperience">{t('questionnaire_modal.history_of_growi_usage')}</label>
  93. <select
  94. name="lengthOfExperience"
  95. id="lengthOfExperience"
  96. className="col-sm-7 form-control"
  97. >
  98. <option value="">▼ {t('Select')}</option>
  99. <option>{t('questionnaire_modal.length_of_experience.more_than_two_years')}</option>
  100. <option>{t('questionnaire_modal.length_of_experience.one_to_two_years')}</option>
  101. <option>{t('questionnaire_modal.length_of_experience.six_months_to_one_year')}</option>
  102. <option>{t('questionnaire_modal.length_of_experience.three_months_to_six_months')}</option>
  103. <option>{t('questionnaire_modal.length_of_experience.one_month_to_three_months')}</option>
  104. <option>{t('questionnaire_modal.length_of_experience.less_than_one_month')}</option>
  105. </select>
  106. </div>
  107. <div className="form-group row mt-3">
  108. <label className="col-sm-5 col-form-label" htmlFor="occupation">{t('questionnaire_modal.occupation')}</label>
  109. <input className="col-sm-7 form-control" type="text" name="occupation" id="occupation" />
  110. </div>
  111. <div className="form-group row mt-3">
  112. <label className="col-sm-5 col-form-label" htmlFor="position">{t('questionnaire_modal.position')}</label>
  113. <input className="col-sm-7 form-control" type="text" name="position" id="position" />
  114. </div>
  115. <div className="form-group row mt-3">
  116. <label className="col-sm-5 col-form-label" htmlFor="commentText">
  117. <span className="badge badge-primary mr-2">{t('questionnaire_modal.required')}</span>{t('questionnaire_modal.comment_on_growi')}
  118. </label>
  119. <textarea className="col-sm-7 form-control" name="commentText" id="commentText" rows={5} required/>
  120. </div>
  121. <div className="text-center mt-5">
  122. <button type="submit" className="btn btn-primary">{t('questionnaire_modal.submit')}</button>
  123. </div>
  124. <div className="text-center my-3">
  125. <span style={{ cursor: 'pointer', textDecoration: 'underline' }} onClick={onClose}>{t('questionnaire_modal.close')}</span>
  126. </div>
  127. </form>
  128. </div>
  129. </ModalBody>
  130. </Modal>
  131. <QuestionnaireCompletionModal isOpen={isQuestionnaireCompletionModal} onClose={() => setQuestionnaireCompletionModal(false)} />
  132. </>
  133. );
  134. };
  135. export default ProactiveQuestionnaireModal;