PluginInstallerForm.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { useCallback } from 'react';
  2. import { toastSuccess, toastError } from '~/client/util/apiNotification';
  3. import { apiv3Post } from '~/client/util/apiv3-client';
  4. // TODO: i18n
  5. export const PluginInstallerForm = (): JSX.Element => {
  6. const submitHandler = useCallback(async(e) => {
  7. e.preventDefault();
  8. const formData = e.target.elements;
  9. const {
  10. 'pluginInstallerForm[url]': { value: url },
  11. // 'pluginInstallerForm[ghBranch]': { value: ghBranch },
  12. // 'pluginInstallerForm[ghTag]': { value: ghTag },
  13. } = formData;
  14. const pluginInstallerForm = {
  15. url,
  16. // ghBranch,
  17. // ghTag,
  18. };
  19. try {
  20. await apiv3Post('/plugins-extension', { pluginInstallerForm });
  21. toastSuccess('Plugin Install Successed!');
  22. }
  23. catch (err) {
  24. toastError(err);
  25. // logger.error(err);
  26. }
  27. }, []);
  28. return (
  29. <form role="form" onSubmit={submitHandler}>
  30. <div className='form-group row'>
  31. <label className="text-left text-md-right col-md-3 col-form-label">GitHub Repository URL</label>
  32. <div className="col-md-6">
  33. <input
  34. className="form-control"
  35. type="text"
  36. name="pluginInstallerForm[url]"
  37. placeholder="https://github.com/weseek/growi-plugin-lsx"
  38. required
  39. />
  40. <p className="form-text text-muted">You can install plugins by inputting the GitHub URL.</p>
  41. </div>
  42. </div>
  43. <div className="row my-3">
  44. <div className="mx-auto">
  45. <button type="submit" className="btn btn-primary">Install</button>
  46. </div>
  47. </div>
  48. </form>
  49. );
  50. };