GcsSetting.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import type { JSX } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import type { UseFormRegister } from 'react-hook-form';
  4. import type { FileUploadFormValues } from './FileUploadSetting.types';
  5. export type GcsSettingMoleculeProps = {
  6. register: UseFormRegister<FileUploadFormValues>
  7. gcsReferenceFileWithRelayMode: boolean
  8. gcsUseOnlyEnvVars: boolean
  9. envGcsApiKeyJsonPath?: string
  10. envGcsBucket?: string
  11. envGcsUploadNamespace?: string
  12. onChangeGcsReferenceFileWithRelayMode: (val: boolean) => void
  13. };
  14. export const GcsSettingMolecule = (props: GcsSettingMoleculeProps): JSX.Element => {
  15. const { t } = useTranslation();
  16. const {
  17. gcsReferenceFileWithRelayMode,
  18. gcsUseOnlyEnvVars,
  19. envGcsApiKeyJsonPath,
  20. envGcsBucket,
  21. envGcsUploadNamespace,
  22. } = props;
  23. return (
  24. <>
  25. <div className="row my-3">
  26. <label className="text-start text-md-end col-md-3 col-form-label">
  27. {t('admin:app_setting.file_delivery_method')}
  28. </label>
  29. <div className="col-md-6">
  30. <div className="dropdown">
  31. <button
  32. className="btn btn-outline-secondary dropdown-toggle"
  33. type="button"
  34. id="ddGcsReferenceFileWithRelayMode"
  35. data-bs-toggle="dropdown"
  36. aria-haspopup="true"
  37. aria-expanded="true"
  38. >
  39. {gcsReferenceFileWithRelayMode && t('admin:app_setting.file_delivery_method_relay')}
  40. {!gcsReferenceFileWithRelayMode && t('admin:app_setting.file_delivery_method_redirect')}
  41. </button>
  42. <div className="dropdown-menu" aria-labelledby="ddGcsReferenceFileWithRelayMode">
  43. <button
  44. className="dropdown-item"
  45. type="button"
  46. onClick={() => { props.onChangeGcsReferenceFileWithRelayMode(true) }}
  47. >
  48. {t('admin:app_setting.file_delivery_method_relay')}
  49. </button>
  50. <button
  51. className="dropdown-item"
  52. type="button"
  53. onClick={() => { props.onChangeGcsReferenceFileWithRelayMode(false) }}
  54. >
  55. {t('admin:app_setting.file_delivery_method_redirect')}
  56. </button>
  57. </div>
  58. <p className="form-text text-muted small">
  59. {t('admin:app_setting.file_delivery_method_redirect_info')}
  60. <br />
  61. {t('admin:app_setting.file_delivery_method_relay_info')}
  62. </p>
  63. </div>
  64. </div>
  65. </div>
  66. {gcsUseOnlyEnvVars && (
  67. <p
  68. className="alert alert-info"
  69. // eslint-disable-next-line react/no-danger
  70. dangerouslySetInnerHTML={{ __html: t('admin:app_setting.note_for_the_only_env_option', { env: 'GCS_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS' }) }}
  71. />
  72. )}
  73. <table className={`table settings-table ${gcsUseOnlyEnvVars && 'use-only-env-vars'}`}>
  74. <colgroup>
  75. <col className="item-name" />
  76. <col className="from-db" />
  77. <col className="from-env-vars" />
  78. </colgroup>
  79. <thead>
  80. <tr>
  81. <th></th>
  82. <th>Database</th>
  83. <th>Environment variables</th>
  84. </tr>
  85. </thead>
  86. <tbody>
  87. <tr>
  88. <th>Api Key Json Path</th>
  89. <td>
  90. <input
  91. className="form-control"
  92. type="text"
  93. readOnly={gcsUseOnlyEnvVars}
  94. {...props.register('gcsApiKeyJsonPath')}
  95. />
  96. </td>
  97. <td>
  98. <input className="form-control" type="text" value={envGcsApiKeyJsonPath || ''} readOnly tabIndex={-1} />
  99. <p className="form-text text-muted">
  100. {/* eslint-disable-next-line react/no-danger */}
  101. <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_API_KEY_JSON_PATH' }) }} />
  102. </p>
  103. </td>
  104. </tr>
  105. <tr>
  106. <th>{t('admin:app_setting.bucket_name')}</th>
  107. <td>
  108. <input
  109. className="form-control"
  110. type="text"
  111. readOnly={gcsUseOnlyEnvVars}
  112. {...props.register('gcsBucket')}
  113. />
  114. </td>
  115. <td>
  116. <input className="form-control" type="text" value={envGcsBucket || ''} readOnly tabIndex={-1} />
  117. <p className="form-text text-muted">
  118. {/* eslint-disable-next-line react/no-danger */}
  119. <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_BUCKET' }) }} />
  120. </p>
  121. </td>
  122. </tr>
  123. <tr>
  124. <th>Name Space</th>
  125. <td>
  126. <input
  127. className="form-control"
  128. type="text"
  129. readOnly={gcsUseOnlyEnvVars}
  130. {...props.register('gcsUploadNamespace')}
  131. />
  132. </td>
  133. <td>
  134. <input className="form-control" type="text" value={envGcsUploadNamespace || ''} readOnly tabIndex={-1} />
  135. <p className="form-text text-muted">
  136. {/* eslint-disable-next-line react/no-danger */}
  137. <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_UPLOAD_NAMESPACE' }) }} />
  138. </p>
  139. </td>
  140. </tr>
  141. </tbody>
  142. </table>
  143. </>
  144. );
  145. };