ProactiveQuestionnaireModal.tsx 6.0 KB

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