PluginInstallerForm.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React, { useCallback } from 'react';
  2. import { toastSuccess, toastError } from '~/client/util/apiNotification';
  3. import { apiv3Post } from '~/client/util/apiv3-client';
  4. import { useSWRxPlugins } from '~/stores/plugin';
  5. // TODO: i18n
  6. export const PluginInstallerForm = (): JSX.Element => {
  7. const { mutate } = useSWRxPlugins();
  8. const submitHandler = useCallback(async(e) => {
  9. e.preventDefault();
  10. const formData = e.target.elements;
  11. const {
  12. 'pluginInstallerForm[url]': { value: url },
  13. // 'pluginInstallerForm[ghBranch]': { value: ghBranch },
  14. // 'pluginInstallerForm[ghTag]': { value: ghTag },
  15. } = formData;
  16. const pluginInstallerForm = {
  17. url,
  18. // ghBranch,
  19. // ghTag,
  20. };
  21. try {
  22. await apiv3Post('/plugins-extension', { pluginInstallerForm });
  23. toastSuccess('Plugin Install Successed!');
  24. }
  25. catch (err) {
  26. toastError(err);
  27. // logger.error(err);
  28. }
  29. finally {
  30. mutate();
  31. }
  32. }, [mutate]);
  33. return (
  34. <form role="form" onSubmit={submitHandler}>
  35. <div className='form-group row'>
  36. <label className="text-left text-md-right col-md-3 col-form-label">GitHub Repository URL</label>
  37. <div className="col-md-6">
  38. <input
  39. className="form-control"
  40. type="text"
  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. </div>
  47. </div>
  48. <div className="row my-3">
  49. <div className="mx-auto">
  50. <button type="submit" className="btn btn-primary">Install</button>
  51. </div>
  52. </div>
  53. </form>
  54. );
  55. };