PluginInstallerForm.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { toastSuccess, toastError } from '~/client/util/apiNotification';
  4. import { apiv3Post } from '~/client/util/apiv3-client';
  5. import AdminInstallButtonRow from '../Common/AdminUpdateButtonRow';
  6. // TODO: error notification (toast, loggerFactory)
  7. // TODO: i18n
  8. export const PluginInstallerForm = (): JSX.Element => {
  9. // const { t } = useTranslation('admin');
  10. const submitHandler = useCallback(async(e) => {
  11. e.preventDefault();
  12. const formData = e.target.elements;
  13. const {
  14. 'pluginInstallerForm[url]': { value: url },
  15. // 'pluginInstallerForm[ghBranch]': { value: ghBranch },
  16. // 'pluginInstallerForm[ghTag]': { value: ghTag },
  17. } = formData;
  18. const pluginInstallerForm = {
  19. url,
  20. // ghBranch,
  21. // ghTag,
  22. };
  23. try {
  24. await apiv3Post('/plugins-extension', { pluginInstallerForm });
  25. toastSuccess('Plugin Install Successed!');
  26. }
  27. catch (err) {
  28. toastError(err);
  29. // logger.error(err);
  30. }
  31. }, []);
  32. return (
  33. <form role="form" onSubmit={submitHandler}>
  34. <div className='form-group row'>
  35. <label className="text-left text-md-right col-md-3 col-form-label">GitHub Repository URL</label>
  36. <div className="col-md-6">
  37. <input
  38. className="form-control"
  39. type="text"
  40. // defaultValue={adminAppContainer.state.title || ''}
  41. name="pluginInstallerForm[url]"
  42. placeholder="https://github.com/weseek/growi-plugin-lsx"
  43. required
  44. />
  45. <p className="form-text text-muted">You can install plugins by inputting the GitHub URL.</p>
  46. {/* <p className="form-text text-muted">{t('admin:app_setting.sitename_change')}</p> */}
  47. </div>
  48. </div>
  49. {/* <div className='form-group row'>
  50. <label className="text-left text-md-right col-md-3 col-form-label">branch</label>
  51. <div className="col-md-6">
  52. <input
  53. className="form-control"
  54. type="text"
  55. name="pluginInstallerForm[ghBranch]"
  56. placeholder="main"
  57. />
  58. <p className="form-text text-muted">branch name</p>
  59. </div>
  60. </div>
  61. <div className='form-group row'>
  62. <label className="text-left text-md-right col-md-3 col-form-label">tag</label>
  63. <div className="col-md-6">
  64. <input
  65. className="form-control"
  66. type="text"
  67. name="pluginInstallerForm[ghTag]"
  68. placeholder="tags"
  69. />
  70. <p className="form-text text-muted">tag name</p>
  71. </div>
  72. </div> */}
  73. <div className="row my-3">
  74. <div className="mx-auto">
  75. <button type="submit" className="btn btn-primary">Install</button>
  76. </div>
  77. </div>
  78. </form>
  79. );
  80. };