From 10b0b7544ceb0dfc6171c3d305413e5156ae8559 Mon Sep 17 00:00:00 2001
From: Deepak
Date: Mon, 19 Apr 2021 12:32:57 -0500
Subject: [PATCH] Adds authenticated app stuff
---
src/components/Plan/index.jsx | 15 ++++++++++++---
src/components/PlanList/index.jsx | 5 +++--
src/screens/AuthenticatedApp.jsx | 29 +++++++++++++++++++++++++++--
3 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/src/components/Plan/index.jsx b/src/components/Plan/index.jsx
index 4749fbb..e4a633c 100644
--- a/src/components/Plan/index.jsx
+++ b/src/components/Plan/index.jsx
@@ -1,17 +1,26 @@
import React from "react";
import PropTypes from "prop-types";
-function Plan({ plan }) {
+function Plan({ initial_plan }) {
+
+ const onChangeDescription = (e) => {
+ const p = {
+ ...plan,
+ plan_description: e.currentTarget.value
+ };
+ savePlan(p);
+ }
+
return (
{plan.plan_id}:
-
Description: {plan.plan_description}
+
);
}
Plan.propTypes = {
- plan: PropTypes.object,
+ plan: PropTypes.object
};
export default Plan;
diff --git a/src/components/PlanList/index.jsx b/src/components/PlanList/index.jsx
index 8079356..c1ae9ec 100644
--- a/src/components/PlanList/index.jsx
+++ b/src/components/PlanList/index.jsx
@@ -2,13 +2,13 @@ import React from "react";
import PropTypes from "prop-types";
import Plan from "../Plan";
-function PlanList({ plans }) {
+function PlanList({ plans, savePlan }) {
return (
{plans.map((plan) => {
return (
-
-
+
);
})}
@@ -18,6 +18,7 @@ function PlanList({ plans }) {
PlanList.propTypes = {
plans: PropTypes.arrayOf(PropTypes.object),
+ savePlan: PropTypes.func
};
export default PlanList;
diff --git a/src/screens/AuthenticatedApp.jsx b/src/screens/AuthenticatedApp.jsx
index 7179302..81c1030 100644
--- a/src/screens/AuthenticatedApp.jsx
+++ b/src/screens/AuthenticatedApp.jsx
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from "react";
import { useAuth, useClient } from "../context/AuthContext";
import "./AuthenticatedApp.scss";
import PlanList from "../components/PlanList";
-import { getPlansFunc } from "../services/plans-service";
+import { getPlansFunc, savePlanFunc } from "../services/plans-service";
function AuthenticatedApp() {
const { logout, user } = useAuth();
@@ -14,6 +14,31 @@ function AuthenticatedApp() {
// const getPlans = getPlansFunc(client);
const getPlans = useCallback(() => getPlansFunc(client)(), [client]);
+ const savePlan = useCallback(
+ (plan) => {
+ console.log("in the callback saveplan func");
+ console.log(plan);
+ return savePlanFunc(client)(plan)
+ }, [client]);
+
+ const updatePlan = (plan) => {
+ savePlan(plan)
+ .then((data) => {
+ console.log("returning from save plan");
+ console.log(data);
+ setError(null);
+ })
+ .catch((error) => {
+ setError(error);
+ })
+ const newPlans = plans.map(currentPlan => {
+ if (currentPlan.plan_id === plan.plan_id) {
+ return plan;
+ }
+ return currentPlan;
+ });
+ setPlans(newPlans);
+ }
useEffect(() => {
setLoading(true);
@@ -40,7 +65,7 @@ function AuthenticatedApp() {
Error: {error || "No errors"}
Loading: {isLoading ? "Loading" : "Not loading"}
-
+
);