GcsSetting.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. isCloud: boolean;
  14. };
  15. export const GcsSettingMolecule = (
  16. props: GcsSettingMoleculeProps,
  17. ): JSX.Element => {
  18. const { t } = useTranslation();
  19. const {
  20. gcsReferenceFileWithRelayMode,
  21. gcsUseOnlyEnvVars,
  22. envGcsApiKeyJsonPath,
  23. envGcsBucket,
  24. envGcsUploadNamespace,
  25. isCloud,
  26. } = props;
  27. return (
  28. <>
  29. <div className="row my-3">
  30. <span className="text-start text-md-end col-md-3 col-form-label">
  31. {t('admin:app_setting.file_delivery_method')}
  32. </span>
  33. <div className="col-md-6">
  34. <div className="dropdown">
  35. <button
  36. className="btn btn-outline-secondary dropdown-toggle"
  37. type="button"
  38. id="ddGcsReferenceFileWithRelayMode"
  39. data-bs-toggle="dropdown"
  40. aria-haspopup="true"
  41. aria-expanded="true"
  42. >
  43. {gcsReferenceFileWithRelayMode &&
  44. t('admin:app_setting.file_delivery_method_relay')}
  45. {!gcsReferenceFileWithRelayMode &&
  46. t('admin:app_setting.file_delivery_method_redirect')}
  47. </button>
  48. <div className="dropdown-menu">
  49. <button
  50. className="dropdown-item"
  51. type="button"
  52. onClick={() => {
  53. props.onChangeGcsReferenceFileWithRelayMode(true);
  54. }}
  55. >
  56. {t('admin:app_setting.file_delivery_method_relay')}
  57. </button>
  58. <button
  59. className="dropdown-item"
  60. type="button"
  61. onClick={() => {
  62. props.onChangeGcsReferenceFileWithRelayMode(false);
  63. }}
  64. >
  65. {t('admin:app_setting.file_delivery_method_redirect')}
  66. </button>
  67. </div>
  68. <p className="form-text text-muted small">
  69. {t('admin:app_setting.file_delivery_method_redirect_info')}
  70. <br />
  71. {t('admin:app_setting.file_delivery_method_relay_info')}
  72. </p>
  73. </div>
  74. </div>
  75. </div>
  76. {gcsUseOnlyEnvVars &&
  77. (isCloud ? (
  78. <p className="alert alert-info">
  79. {t('admin:app_setting.note_for_the_only_env_option_cloud')}
  80. </p>
  81. ) : (
  82. <p
  83. className="alert alert-info"
  84. // biome-ignore lint/security/noDangerouslySetInnerHtml: includes markup from i18n strings
  85. dangerouslySetInnerHTML={{
  86. __html: t('admin:app_setting.note_for_the_only_env_option', {
  87. env: 'GCS_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS',
  88. }),
  89. }}
  90. />
  91. ))}
  92. <table
  93. className={`table settings-table ${gcsUseOnlyEnvVars && 'use-only-env-vars'}`}
  94. >
  95. <colgroup>
  96. <col className="item-name" />
  97. <col className="from-db" />
  98. <col className="from-env-vars" />
  99. </colgroup>
  100. <thead>
  101. <tr>
  102. <th></th>
  103. <th>Database</th>
  104. <th>Environment variables</th>
  105. </tr>
  106. </thead>
  107. <tbody>
  108. <tr>
  109. <th>Api Key Json Path</th>
  110. <td>
  111. <input
  112. className="form-control"
  113. type="text"
  114. readOnly={gcsUseOnlyEnvVars}
  115. {...props.register('gcsApiKeyJsonPath')}
  116. />
  117. </td>
  118. <td>
  119. <input
  120. className="form-control"
  121. type="text"
  122. value={envGcsApiKeyJsonPath || ''}
  123. readOnly
  124. tabIndex={-1}
  125. />
  126. <p className="form-text text-muted">
  127. <small
  128. // biome-ignore lint/security/noDangerouslySetInnerHtml: includes markup from i18n strings
  129. dangerouslySetInnerHTML={{
  130. __html: t('admin:app_setting.use_env_var_if_empty', {
  131. variable: 'GCS_API_KEY_JSON_PATH',
  132. }),
  133. }}
  134. />
  135. </p>
  136. </td>
  137. </tr>
  138. <tr>
  139. <th>{t('admin:app_setting.bucket_name')}</th>
  140. <td>
  141. <input
  142. className="form-control"
  143. type="text"
  144. readOnly={gcsUseOnlyEnvVars}
  145. {...props.register('gcsBucket')}
  146. />
  147. </td>
  148. <td>
  149. <input
  150. className="form-control"
  151. type="text"
  152. value={envGcsBucket || ''}
  153. readOnly
  154. tabIndex={-1}
  155. />
  156. <p className="form-text text-muted">
  157. <small
  158. // biome-ignore lint/security/noDangerouslySetInnerHtml: includes markup from i18n strings
  159. dangerouslySetInnerHTML={{
  160. __html: t('admin:app_setting.use_env_var_if_empty', {
  161. variable: 'GCS_BUCKET',
  162. }),
  163. }}
  164. />
  165. </p>
  166. </td>
  167. </tr>
  168. <tr>
  169. <th>Name Space</th>
  170. <td>
  171. <input
  172. className="form-control"
  173. type="text"
  174. readOnly={gcsUseOnlyEnvVars}
  175. {...props.register('gcsUploadNamespace')}
  176. />
  177. </td>
  178. <td>
  179. <input
  180. className="form-control"
  181. type="text"
  182. value={envGcsUploadNamespace || ''}
  183. readOnly
  184. tabIndex={-1}
  185. />
  186. <p className="form-text text-muted">
  187. <small
  188. // biome-ignore lint/security/noDangerouslySetInnerHtml: includes markup from i18n strings
  189. dangerouslySetInnerHTML={{
  190. __html: t('admin:app_setting.use_env_var_if_empty', {
  191. variable: 'GCS_UPLOAD_NAMESPACE',
  192. }),
  193. }}
  194. />
  195. </p>
  196. </td>
  197. </tr>
  198. </tbody>
  199. </table>
  200. </>
  201. );
  202. };