Skip to content

Commit

Permalink
Added no internet error message
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravmpk committed Jan 23, 2024
1 parent aa9f53c commit 1727414
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions frontend/app/src/components/form/bounty/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Form(props: FormProps) {
const { main, ui } = useStores();
const color = colors['light'];
const [isFocused, setIsFocused] = useState({});

const [isOnline, setIsOnline] = useState(navigator.onLine);
const [schemaData, setSchemaData] = useState(BountyDetailsCreationData.step_1);
const [stepTracker, setStepTracker] = useState<number>(1);

Expand Down Expand Up @@ -99,6 +99,19 @@ function Form(props: FormProps) {
})();
}, []);

useEffect(() => {
const handleOnline = () => setIsOnline(true);
const handleOffline = () => setIsOnline(false);

window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);

return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
};
}, []);

useEffect(() => {
const dSchema = props.schema?.find((f: any) => f.defaultSchema);
const type = initialValues?.type;
Expand Down Expand Up @@ -210,7 +223,28 @@ function Form(props: FormProps) {
const valid = schemaData.required.every((key: string) =>
key === '' ? true : values?.[key]
);

const onClickHandler = () => {
if (!isOnline) {
alert("No internet connection. Please try again later.");
return;
}

// Your existing logic for handling the button click
if (schemaData.step === 5 && valid) {
if (dynamicSchemaName) {
setFieldValue('type', dynamicSchemaName);
}
if (assigneeName !== '') {
handleSubmit();
} else {
setAssigneeName('a');
}
} else {
if (valid) {
NextStepHandler();
}
}
};
const isBtnDisabled = (stepTracker === 3 && !isDescriptionValid) || !valid;

// returns the body of a form page
Expand Down Expand Up @@ -565,22 +599,7 @@ function Form(props: FormProps) {
{!isBtnDisabled && (
<div
className="nextButton"
onClick={() => {
if (schemaData.step === 5 && valid) {
if (dynamicSchemaName) {
setFieldValue('type', dynamicSchemaName);
}
if (assigneeName !== '') {
handleSubmit();
} else {
setAssigneeName('a');
}
} else {
if (valid) {
NextStepHandler();
}
}
}}
onClick={onClickHandler}
style={{
width:
schemaData.step === 5
Expand Down

0 comments on commit 1727414

Please sign in to comment.