79087830

Date: 2024-10-14 22:00:55
Score: 0.5
Natty:
Report link

@MarkRhodes, you are right! I tried it myself and it worked! Here is my index.html file:

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <title>Alex's Invitations App</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel" lang="ts">
      function unfortunately(value, wanted) {
        if (wanted !== value) {
          return value;
        };
      };

      function useEmail(name, email, coming, trusted) {
        const previousUrl = window.location.href;
        const subject = "Invites App";
        // ??????????
        const body = "Name: " + name + escape('\r\n') + "Email: " + email + escape('\r\n') + "Coming: " + coming;
        function send() {
          if (trusted) {
            window.open(`mailto:[email protected]?subject=${subject}&body=${body}`);
            return {
              status: { code: 200 },
              sucess: true,
              responseHeaders: { "type": "application/json" },
              cancelled: false
            };
          };
        };
        
        function cancel() {
          window.open(previousUrl);
          return {
            status: { code: 500 },
            success: true,
            cancelled: true
          };
        };

        return { send, cancel };
      };

      function App() {
        const [ name, setName ] = React.useState("");
        const [ email, setEmail ] = React.useState("");
        const [ coming, setComing ] = React.useState(false); 
        const [ formData, setFormData ] = React.useState({});
        const onSubmit = (e) => {
          e.preventDefault();
          setFormData({
            name,
            email,
            coming
          });

          const { send, cancel } = useEmail(formData.name, formData.email, formData.coming, true);
          const res = send();
          console.log(res);
        };

        return (
          <>
            <h1>Welcome to my app!</h1>
            <form onSubmit={onSubmit}>
              <label htmlFor="name">Name:</label><br /><br />
              <input value={name} type="text" onChange={(e) => setName(e.target.value)} required={true} /><br /><br />
              <label htmlFor="email">Email:</label><br /><br />
              <input value={email} type="email" onChange={(e) => setEmail(e.target.value)} /><br /><br />
              <label htmlFor="coming">Are you coming?</label>{" "}
              <input value={coming} type="checkbox" onChange={(e) => setComing(e.target.checked)} /><br /><br />
              <input type="submit" />
            </form>
          </>
        );
      };

      const container = document.getElementById('root');
      const root = ReactDOM.createRoot(container);
      root.render(<App />);
    </script>
  </body>
</html>

`
Reasons:
  • Blacklisted phrase (1): ???
  • Whitelisted phrase (-1): it worked
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @MarkRhodes
  • Low reputation (1):
Posted by: Alexander Messiha