All files / app/features/auth/signup CommunityGuidelinesForm.tsx

100% Statements 14/14
75% Branches 3/4
100% Functions 5/5
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 402x 2x 2x   2x 2x   2x 12x   12x   3x       2x       3x     3x         12x           3x          
import Alert from "components/Alert";
import { useAuthContext } from "features/auth/AuthProvider";
import CommunityGuidelines from "features/auth/CommunityGuidelines";
import { RpcError } from "grpc-web";
import { useMutation } from "react-query";
import { service } from "service";
 
export default function CommunityGuidelinesForm() {
  const { authActions, authState } = useAuthContext();
 
  const mutation = useMutation<void, RpcError, boolean>(
    async (accept) => {
      const state = await service.auth.signupFlowCommunityGuidelines(
        authState.flowState!.flowToken,
        accept
      );
      authActions.updateSignupState(state);
    },
    {
      onMutate() {
        authActions.clearError();
      },
      onSettled() {
        window.scroll({ top: 0, behavior: "smooth" });
      },
    }
  );
 
  return (
    <>
      {mutation.error && (
        <Alert severity="error">{mutation.error.message || ""}</Alert>
      )}
      <CommunityGuidelines
        onSubmit={(accept) => mutation.mutateAsync(accept)}
      />
    </>
  );
}