PluginInstallerForm.tsx 1.7 KB

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