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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | 14x 13x 13x 1x 1x 1x 13x 1x 13x 14x 14x 14x 13x 13x 13x 13x 13x 13x 13x 14x 14x 14x | import React from "react";
import { Box, Stack } from "@mui/material";
import { styled, useAppTheme } from "@theme/v2/Provider";
import GiveText from "@shared/Text/GiveText";
import GiveButton from "@shared/Button/GiveButton";
import GiveLink from "@shared/Link/GiveLink";
import { NavigateFunction } from "react-router-dom";
import { ExclamationMarkIcon } from "@phosphor-icons/react";
interface PaymentErrorFallbackProps {
error: Error;
resetErrorBoundary: () => void;
formId?: string;
isCritical?: boolean;
navigate?: NavigateFunction;
isBottomSheet?: boolean;
}
/**
* PaymentErrorFallback - User-friendly error UI for payment failures
*
* Provides clear guidance and safe recovery options when payment components crash
*/
const PaymentErrorFallback: React.FC<PaymentErrorFallbackProps> = ({
resetErrorBoundary,
formId,
isCritical = true,
navigate,
isBottomSheet = false,
}) => {
const theme = useAppTheme();
const handleReturnHome = () => {
// If inside a bottom sheet modal, refresh the page to reset everything
Eif (isBottomSheet) {
window.location.reload();
return;
}
// Otherwise, navigate to form or home
if (formId && navigate) {
navigate(`/${formId}`);
} else if (navigate) {
navigate("/");
}
};
const handleContactSupport = () => {
window.location.href = "mailto:support@givepayments.com";
};
return (
<StyledContainer>
<StyledContentWrapper>
{/* Error Icon and Title */}
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
<StyledIconWrapper>
<StyledErrorIcon size={32} weight="light" />
</StyledIconWrapper>
<GiveText variant="h3" color="primary" sx={{ fontWeight: 300 }}>
{isCritical ? "Payment Processing Error" : "Something Went Wrong"}
</GiveText>
</Box>
{/* Error Message */}
<GiveText variant="bodyS" color="primary" sx={{ textAlign: "center" }}>
{isCritical
? "We encountered an issue processing your payment. Your card has not been charged. Please try again or contact support if the problem persists."
: "An unexpected error occurred. Don't worry, your information is safe."}
</GiveText>
{/* Action Buttons */}
<StyledButtonGroup>
<GiveButton
size="large"
label={
<GiveText
variant="bodyS"
sx={{
color: theme.palette.text.invert,
}}
>
Try Again
</GiveText>
}
onClick={resetErrorBoundary}
/>
{formId && (
<GiveButton
variant="outline"
size="large"
label={<GiveText variant="bodyS">Return to Form</GiveText>}
onClick={handleReturnHome}
/>
)}
<GiveLink
component="button"
color="secondary"
onClick={handleContactSupport}
sx={{ textDecoration: "underline" }}
>
<GiveText variant="bodyS" color="secondary">
Contact Support
</GiveText>
</GiveLink>
</StyledButtonGroup>
{/* Safety Message */}
<Box
sx={{ display: "flex", alignItems: "center", gap: 1, marginTop: 2 }}
>
<StyledSuccessIcon
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
>
<path d="M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 10.99h7c-.53 4.12-3.28 7.79-7 8.94V12H5V6.3l7-3.11v8.8z" />
</StyledSuccessIcon>
<GiveText variant="bodyS" color="secondary">
Your payment information is secure and has not been stored.
</GiveText>
</Box>
</StyledContentWrapper>
</StyledContainer>
);
};
// Styled Components
const StyledContainer = styled(Box)(({ theme }) => ({
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: "400px",
width: "100%",
padding: theme.spacing(4),
}));
const StyledContentWrapper = styled(Stack)(({ theme }) => ({
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: theme.spacing(3),
maxWidth: "600px",
width: "100%",
}));
const StyledIconWrapper = styled(Box)(({ theme }) => {
const errorColor = theme.palette.primitive?.error?.["50"];
// Convert hex to rgba with 10% opacity
const hexToRgba = (hex: string, alpha: number) => {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
};
return {
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "48px",
height: "48px",
borderRadius: "50%",
backgroundColor: errorColor ? hexToRgba(errorColor, 0.1) : undefined,
};
});
const StyledErrorIcon = styled(ExclamationMarkIcon)(({ theme }) => ({
color: theme.palette.primitive?.error?.["50"],
}));
const StyledButtonGroup = styled(Stack)(({ theme }) => ({
display: "flex",
flexDirection: "column",
gap: theme.spacing(2),
width: "100%",
maxWidth: "300px",
marginTop: theme.spacing(2),
}));
const StyledSuccessIcon = styled("svg")(({ theme }) => ({
"& path": {
fill: theme.palette.primitive?.success?.["50"],
},
}));
export default PaymentErrorFallback;
|