Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike: form challenges api (front-end) #7495

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

jonwaldstein
Copy link
Contributor

@jonwaldstein jonwaldstein commented Aug 20, 2024

Resolves GIVE-1117

Description

This is currently a WIP...

This adds a (front-end) form challenges api to the donation form. The backend still utilizes our existing validation framework.

useEffect(() => {
    const challenge = {
      id: inputProps.name,
      async execute(setValue) {
        const prompt = window.prompt('What is the secret code?');
        const validated = prompt === '1234';

        if (validated) {
          setValue(prompt);

          return true;
        }

        setValue(null);

        return false;
      }
    };

    window.givewp.form.challenges.register(challenge);

    return () => {
      window.givewp.form.challenges.unregiste
      r(challenge);
    };

  }, []);

Affects

The donation form validation

Visuals

import {useEffect} from 'react';

export default function Field({
   Label,
   ErrorMessage,
   fieldError,
   inputProps
 }) {

  const formState = window.givewp.form.hooks.useFormState();
  const {submitCount} = formState;

  useEffect(() => {
    const challenge = {
      id: inputProps.name,
      async execute(setValue) {
        const prompt = window.prompt('What is the secret code?');
        const validated = prompt === '1234';

        if (validated) {
          setValue(prompt);

          return true;
        }

        setValue(null);

        return false;
      }
    };

    window.givewp.form.challenges.register(challenge);

    return () => {
      window.givewp.form.challenges.unregister(challenge);
    };

  }, [submitCount]);

  return (
    <label className={fieldError && 'givewp-field-error-label'}>
      <input type="hidden" {...inputProps} defaultValue={'123'} />

      <ErrorMessage />
    </label>
  );
}

Testing Instructions

WIP

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

@jonwaldstein jonwaldstein changed the title Spike: form challenges api Spike: form challenges api (front-end) Aug 20, 2024
Copy link

github-actions bot commented Nov 2, 2024

This PR is stale because it has been open 45 days with no activity. Stale PRs will NOT be automatically closed.

@github-actions github-actions bot added the Stale label Nov 2, 2024
@github-actions github-actions bot removed the Stale label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant