ShareLinkForm.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import React from 'react';
  2. import { withTranslation } from 'react-i18next';
  3. import dateFnsFormat from 'date-fns/format';
  4. import { withUnstatedContainers } from './UnstatedUtils';
  5. import AppContainer from '../services/AppContainer';
  6. import PageContainer from '../services/PageContainer';
  7. class ShareLinkForm extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. expirationType: 'unlimited',
  12. numberOfDays: 7,
  13. description: '',
  14. customExpirationDate: dateFnsFormat(new Date(), 'yyyy-MM-dd'),
  15. customExpirationTime: dateFnsFormat(new Date(), 'hh:mm:s'),
  16. };
  17. this.handleChangeExpirationType = this.handleChangeExpirationType.bind(this);
  18. this.handleChangeNumberOfDays = this.handleChangeNumberOfDays.bind(this);
  19. this.handleChangeDescription = this.handleChangeDescription.bind(this);
  20. this.handleIssueShareLink = this.handleIssueShareLink.bind(this);
  21. }
  22. /**
  23. * change expirationType
  24. * @param {string} expirationType
  25. */
  26. handleChangeExpirationType(expirationType) {
  27. this.setState({ expirationType });
  28. }
  29. /**
  30. * change numberOfDays
  31. * @param {number} numberOfDays
  32. */
  33. handleChangeNumberOfDays(numberOfDays) {
  34. this.setState({ numberOfDays });
  35. }
  36. /**
  37. * change description
  38. * @param {string} description
  39. */
  40. handleChangeDescription(description) {
  41. this.setState({ description });
  42. }
  43. /**
  44. * change customExpirationDate
  45. * @param {date} customExpirationDate
  46. */
  47. handleChangeCustomExpirationDate(customExpirationDate) {
  48. this.setState({ customExpirationDate });
  49. }
  50. /**
  51. * change customExpirationTime
  52. * @param {date} customExpirationTime
  53. */
  54. handleChangeCustomExpirationTime(customExpirationTime) {
  55. this.setState({ customExpirationTime });
  56. }
  57. handleIssueShareLink() {
  58. // use these options
  59. console.log(this.state);
  60. console.log('発行する!');
  61. }
  62. renderExpirationTypeOptions() {
  63. const { expirationType } = this.state;
  64. return (
  65. <div className="form-group">
  66. <div className="custom-control custom-radio offset-4 mb-2">
  67. <input
  68. type="radio"
  69. className="custom-control-input"
  70. id="customRadio1"
  71. name="expirationType"
  72. value="customRadio1"
  73. checked={expirationType === 'unlimited'}
  74. onChange={() => { this.handleChangeExpirationType('unlimited') }}
  75. />
  76. <label className="custom-control-label" htmlFor="customRadio1">Unlimited</label>
  77. </div>
  78. <div className="custom-control custom-radio offset-4 mb-2">
  79. <input
  80. type="radio"
  81. className="custom-control-input"
  82. id="customRadio2"
  83. value="customRadio2"
  84. checked={expirationType === 'numberOfDays'}
  85. onChange={() => { this.handleChangeExpirationType('numberOfDays') }}
  86. name="expirationType"
  87. />
  88. <label className="custom-control-label" htmlFor="customRadio2">
  89. <div className="row align-items-center m-0">
  90. <input
  91. type="number"
  92. min="1"
  93. className="col-4"
  94. name="expirationType"
  95. value={this.state.numberOfDays}
  96. onFocus={() => { this.handleChangeExpirationType('numberOfDays') }}
  97. onChange={e => this.handleChangeNumberOfDays(Number(e.target.value))}
  98. />
  99. <span className="col-auto">Days</span>
  100. </div>
  101. </label>
  102. </div>
  103. <div className="custom-control custom-radio offset-4 mb-2">
  104. <input
  105. type="radio"
  106. className="custom-control-input"
  107. id="customRadio3"
  108. name="expirationType"
  109. value="customRadio3"
  110. checked={expirationType === 'custom'}
  111. onChange={() => { this.handleChangeExpirationType('custom') }}
  112. />
  113. <label className="custom-control-label" htmlFor="customRadio3">
  114. Custom
  115. </label>
  116. <input
  117. type="date"
  118. className="ml-3"
  119. name="customExpirationDate"
  120. value={this.state.customExpirationDate}
  121. onFocus={() => { this.handleChangeExpirationType('custom') }}
  122. onChange={e => this.handleChangeCustomExpirationDate(e.target.value)}
  123. />
  124. <input
  125. type="time"
  126. className="ml-3"
  127. name="customExpiration"
  128. value={this.state.customExpirationTime}
  129. onFocus={() => { this.handleChangeExpirationType('custom') }}
  130. onChange={e => this.handleChangeCustomExpirationTime(e.target.value)}
  131. />
  132. </div>
  133. </div>
  134. );
  135. }
  136. renderDescriptionForm() {
  137. return (
  138. <div className="form-group row">
  139. <label htmlFor="inputDesc" className="col-md-4 col-form-label">Description</label>
  140. <div className="col-md-4">
  141. <input
  142. type="text"
  143. className="form-control"
  144. id="inputDesc"
  145. placeholder="Enter description"
  146. value={this.state.description}
  147. onChange={e => this.handleChangeDescription(e.target.value)}
  148. />
  149. </div>
  150. </div>
  151. );
  152. }
  153. render() {
  154. return (
  155. <div className="share-link-form border p-3">
  156. <h4>Expiration Date</h4>
  157. {this.renderExpirationTypeOptions()}
  158. <hr />
  159. {this.renderDescriptionForm()}
  160. <div className="text-right">
  161. <button type="button" className="btn btn-primary" onClick={this.handleIssueShareLink}>
  162. Issue
  163. </button>
  164. </div>
  165. </div>
  166. );
  167. }
  168. }
  169. const ShareLinkFormWrapper = withUnstatedContainers(ShareLinkForm, [AppContainer, PageContainer]);
  170. export default withTranslation()(ShareLinkFormWrapper);