|
@@ -12,6 +12,7 @@ import Loading from "../Loading";
|
|
|
import DoneButton from "../Buttons/DoneButton";
|
|
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
|
|
import { getSinglePlan } from "./plans.util";
|
|
|
+import SavingButton from "../Buttons/SavingButton";
|
|
|
|
|
|
/** Dialog page that allows user to edit plan */
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
@@ -39,7 +40,7 @@ const inverseColors = true;
|
|
|
const serverURL = process.env.REACT_APP_SERVER_URL;
|
|
|
|
|
|
/** page that allows editing a plan */
|
|
|
-const EditPlanItem = (props) => {
|
|
|
+const EditPlanItem = () => {
|
|
|
const classes = useStyles();
|
|
|
const { t } = useTranslation();
|
|
|
const { state } = useLocation();
|
|
@@ -47,8 +48,7 @@ const EditPlanItem = (props) => {
|
|
|
let { planItemId } = useParams();
|
|
|
const { user } = useAuth0();
|
|
|
|
|
|
- console.log(state, planItemId);
|
|
|
-
|
|
|
+ const [isSaving, setIsSaving] = useState(false);
|
|
|
const [planItem, setPlanItem] = useState((state && state.planItem) ? state.planItem : null);
|
|
|
|
|
|
// get planItem if it is not there
|
|
@@ -72,8 +72,11 @@ const EditPlanItem = (props) => {
|
|
|
connectedMealId: planItem.connectedMeal ? planItem.connectedMeal._id : null,
|
|
|
}
|
|
|
|
|
|
+ setIsSaving(true);
|
|
|
axios.post(serverURL + '/plans/edit/' + planItem._id, newPlan).then((result) => {
|
|
|
- console.log('edit request sent', result.data);
|
|
|
+ // editing done
|
|
|
+ setIsSaving(false);
|
|
|
+ goBackToPlans();
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -89,7 +92,6 @@ const EditPlanItem = (props) => {
|
|
|
const editAndClose = (event) => {
|
|
|
event.preventDefault();
|
|
|
editPlan();
|
|
|
- goBackToPlans();
|
|
|
}
|
|
|
|
|
|
const goBackToPlans = () => {
|
|
@@ -97,7 +99,6 @@ const EditPlanItem = (props) => {
|
|
|
}
|
|
|
|
|
|
const updatePlanItem = (key, value) => {
|
|
|
- console.log('editing', key, 'to', value);
|
|
|
setPlanItem(prevState => ({
|
|
|
...prevState,
|
|
|
[key]: value,
|
|
@@ -122,7 +123,7 @@ const EditPlanItem = (props) => {
|
|
|
<DeleteButton onClick={deletePlan} />
|
|
|
</Grid>
|
|
|
<Grid item xs className={classes.saveButton}>
|
|
|
- <Button type="submit" disabled={!planItem.title} color={inverseColors ? "secondary" : "primary"} variant="contained">{t('Save')}</Button>
|
|
|
+ <SavingButton isSaving={isSaving} type="submit" disabled={!planItem.title} color={inverseColors ? "secondary" : "primary"} variant="contained">{t('Save')}</SavingButton>
|
|
|
</Grid>
|
|
|
</Grid>
|
|
|
</form>
|