Skip to content

Commit

Permalink
Hide error message when value changes
Browse files Browse the repository at this point in the history
  • Loading branch information
britneywwc committed Mar 4, 2024
1 parent 118a569 commit 9303cc5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { Formik } from "formik";
import {
Col,
Expand Down Expand Up @@ -32,6 +32,33 @@ const Checkout = ({ product, quantity, action }: Props) => {
const canTrial = canBeTrialled(productCanBeTrialled, userCanTrial);
const initialValues = getInitialFormValues(product, canTrial, userInfo);

useEffect(() => {
const handleInputChange = () => {
error ? setError(null) : null;
};

const inputElements = document.querySelectorAll("input");
const selectElements = document.querySelectorAll("select");

inputElements.forEach((input) => {
input.addEventListener("change", handleInputChange);
});

selectElements.forEach((select) => {
select.addEventListener("change", handleInputChange);
});

return () => {
inputElements.forEach((input) => {
input.removeEventListener("change", handleInputChange);
});

selectElements.forEach((select) => {
select.removeEventListener("change", handleInputChange);
});
};
}, [error]);

if (!localStorage.getItem("gaEventTriggered")) {
localStorage.setItem("gaEventTriggered", "true");
checkoutEvent(window.GAFriendlyProduct, "2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const UserInfoForm = ({ setError }: Props) => {
queryClient.invalidateQueries("preview");
setIsButtonDisabled(false);
setIsEditing(false);
setError(null);

Check warning on line 93 in static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.tsx

View check run for this annotation

Codecov / codecov/patch

static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.tsx#L93

Added line #L93 was not covered by tests
},
onError: (error) => {
setFieldValue("Description", false);
Expand Down
32 changes: 16 additions & 16 deletions templates/account/checkout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
endblock meta_copydoc %} {% block content %}

<div id="shop-checkout-app">
<div class="p-strip">
<div class="u-fixed-width">
<h1 class="p-heading--2">
Checkout
</h1>
</div>
<div class="p-strip">
<div class="u-fixed-width">
<h1 class="p-heading--2">
Checkout
</h1>
</div>
<div class="p-strip u-no-padding--top">
<div class="row">
<div class="u-no-margin--bottom p-card">
<div class="p-card__content">
<span class="p-text--default">
<i class="p-icon--spinner u-animation--spin"></i>
</span>
Loading…
</div>
</div>
</div>
<div class="p-strip u-no-padding--top">
<div class="row">
<div class="u-no-margin--bottom p-card">
<div class="p-card__content">
<span class="p-text--default">
<i class="p-icon--spinner u-animation--spin"></i>
</span>
Loading…
</div>
</div>
</div>
</div>
</div>

<script>
Expand Down

0 comments on commit 9303cc5

Please sign in to comment.