report.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { useFormState } from "react-use-form-state";
  2. import { Flex } from "reflexbox/styled-components";
  3. import React, { useState } from "react";
  4. import axios from "axios";
  5. import Text, { H2, Span } from "../components/Text";
  6. import AppWrapper from "../components/AppWrapper";
  7. import { TextInput } from "../components/Input";
  8. import { Button } from "../components/Button";
  9. import { Col } from "../components/Layout";
  10. import Icon from "../components/Icon";
  11. import { useMessage } from "../hooks";
  12. import { API } from "../consts";
  13. const ReportPage = () => {
  14. const [formState, { text }] = useFormState<{ url: string }>();
  15. const [loading, setLoading] = useState(false);
  16. const [message, setMessage] = useMessage(5000);
  17. const onSubmit = async e => {
  18. e.preventDefault();
  19. setLoading(true);
  20. setMessage();
  21. try {
  22. await axios.post(API.REPORT, { link: formState.values.url }); // TODO: better api calls
  23. setMessage("Thanks for the report, we'll take actions shortly.", "green");
  24. formState.clear();
  25. } catch (error) {
  26. setMessage(error?.response?.data?.error || "Couldn't send report.");
  27. }
  28. setLoading(false);
  29. };
  30. return (
  31. <AppWrapper>
  32. <Col width={600} maxWidth="97%" alignItems="flex-start">
  33. <H2 my={3} bold>
  34. Report abuse
  35. </H2>
  36. <Text mb={3}>
  37. Report abuses, malware and phishing links to the below email address
  38. or use the form. We will take actions shortly.
  39. </Text>
  40. <Text mb={4}>
  41. {(process.env.REPORT_EMAIL || "").replace("@", "[at]")}
  42. </Text>
  43. <Text mb={3}>
  44. <Span bold>URL containing malware/scam:</Span>
  45. </Text>
  46. <Flex
  47. as="form"
  48. flexDirection={["column", "row"]}
  49. alignItems={["flex-start", "center"]}
  50. justifyContent="flex-start"
  51. onSubmit={onSubmit}
  52. >
  53. <TextInput
  54. {...text("url")}
  55. placeholder="kutt.it/example"
  56. height={[44, 54]}
  57. width={[1, 1 / 2]}
  58. flex="0 0 auto"
  59. mr={3}
  60. required
  61. />
  62. <Button type="submit" flex="0 0 auto" height={[40, 44]} mt={[3, 0]}>
  63. {loading && <Icon name={"spinner"} stroke="white" mr={2} />}
  64. Send report
  65. </Button>
  66. </Flex>
  67. <Text fontSize={14} mt={3} color={message.color}>
  68. {message.text}
  69. </Text>
  70. </Col>
  71. </AppWrapper>
  72. );
  73. };
  74. export default ReportPage;