Skip to content

Commit

Permalink
feat: add prompt to save work
Browse files Browse the repository at this point in the history
Add prompt to save when user clicks the "Back to {locale} {locale-code}
Sim List" button.

See #341.

Part of phetsims/qa#869.
  • Loading branch information
liammulh committed Dec 21, 2022
1 parent a231379 commit fc6c136
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/client/components/TranslationForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import React, {
useEffect,
useState
} from 'react';
import { useParams, Link } from 'react-router-dom';
import { useParams, useNavigate } from 'react-router-dom';
import publicConfig from '../../common/publicConfig.js';
import makeValidationSchema from '../js/makeValidationSchema.js';
import saveTranslation from '../js/saveTranslation.js';
Expand Down Expand Up @@ -55,6 +55,14 @@ const TranslationForm = () => {
}
}, [ websiteUserData ] );

const navigate = useNavigate();
const handleBackToSimList = () => {
const message = 'If you have unsaved work, it will be lost. Are you sure you want to proceed?';
if ( window.confirm( message ) ) {
navigate( `/translate/${params.locale}` );
}
};

const [ isDisabled, setIsDisabled ] = useState( false );
const [ buttonId, setButtonId ] = useState( '' );
const handleButtonClick = evt => {
Expand Down Expand Up @@ -97,7 +105,7 @@ const TranslationForm = () => {
locale={params.locale}
simTitle={simTitle}
/>
<Link to={`/translate/${params.locale}`}>Back to {localeName} ({params.locale}) Sim List</Link>
<button onClick={handleBackToSimList} className='btn btn-primary'>Back to {localeName} ({params.locale}) Sim List</button>
<Formik
initialValues={translationFormData}
validationSchema={validationSchema}
Expand Down

0 comments on commit fc6c136

Please sign in to comment.