Skip to content

Commit

Permalink
proper noCancel pass
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarkhatov committed Aug 12, 2024
1 parent 0309c2b commit 46ef129
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/app/components/Modals/ErrorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ErrorModal: React.FC<ErrorModalProps> = ({
errorMessage,
errorState,
noCancel,
errorTime,
// errorTime, // This prop is not used in the component
}) => {
const { error, retryErrorAction } = useError();

Expand Down Expand Up @@ -95,7 +95,7 @@ export const ErrorModal: React.FC<ErrorModalProps> = ({
<p className="text-center">{getErrorMessage()}</p>
</div>
<div className="mt-4 flex justify-around gap-4">
{noCancel && (
{!noCancel && ( // Only show the cancel button if noCancel is false or undefined
<button
className="btn btn-outline flex-1 rounded-lg px-2"
onClick={() => onClose()}
Expand Down
18 changes: 13 additions & 5 deletions src/app/context/Error/ErrorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ interface ErrorContextType {
retryErrorAction?: () => void;
showError: (showErrorParams: ShowErrorParams) => void;
hideError: () => void;
noCancel?: boolean;
}

export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
const [isErrorOpen, setIsErrorOpen] = useState(false);
const [isNoCancel, setIsNoCancel] = useState(false);
const [error, setError] = useState<ErrorType>({
message: "",
errorTime: new Date(),
Expand All @@ -33,11 +35,15 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
(() => void) | undefined
>();

const showError = useCallback(({ error, retryAction }: ShowErrorParams) => {
setError(error);
setIsErrorOpen(true);
setRetryErrorAction(() => retryAction);
}, []);
const showError = useCallback(
({ error, retryAction, noCancel }: ShowErrorParams) => {
setError(error);
setIsErrorOpen(true);
setIsNoCancel(noCancel ?? false);
setRetryErrorAction(() => retryAction);
},
[],
);

const hideError = useCallback(() => {
setIsErrorOpen(false);
Expand All @@ -48,6 +54,7 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
errorState: undefined,
});
setRetryErrorAction(undefined);
setIsNoCancel(false);
}, 300);
}, []);

Expand All @@ -57,6 +64,7 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
showError,
hideError,
retryErrorAction,
noCancel: isNoCancel,
};

return (
Expand Down
11 changes: 9 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ const Home: React.FC<HomeProps> = () => {
const [publicKeyNoCoord, setPublicKeyNoCoord] = useState("");

const [address, setAddress] = useState("");
const { error, isErrorOpen, showError, hideError, retryErrorAction } =
useError();
const {
error,
isErrorOpen,
showError,
hideError,
retryErrorAction,
noCancel,
} = useError();
const { isTermsOpen, closeTerms } = useTerms();

const {
Expand Down Expand Up @@ -470,6 +476,7 @@ const Home: React.FC<HomeProps> = () => {
errorTime={error.errorTime}
onClose={hideError}
onRetry={retryErrorAction}
noCancel={noCancel}
/>
<TermsModal open={isTermsOpen} onClose={closeTerms} />
</main>
Expand Down

0 comments on commit 46ef129

Please sign in to comment.