Adds authenticated app stuff
Some checks failed
gitea-deepak/gog_frontend/pipeline/head There was a failure building this commit
Some checks failed
gitea-deepak/gog_frontend/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -1,17 +1,26 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
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 (
|
return (
|
||||||
<div className="plan-wrapper">
|
<div className="plan-wrapper">
|
||||||
<p>{plan.plan_id}: </p>
|
<p>{plan.plan_id}: </p>
|
||||||
<p>Description: {plan.plan_description}</p>
|
<input type="text" onChange={onChangeDescription} value={plan.plan_description}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plan.propTypes = {
|
Plan.propTypes = {
|
||||||
plan: PropTypes.object,
|
plan: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Plan;
|
export default Plan;
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import React from "react";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import Plan from "../Plan";
|
import Plan from "../Plan";
|
||||||
|
|
||||||
function PlanList({ plans }) {
|
function PlanList({ plans, savePlan }) {
|
||||||
return (
|
return (
|
||||||
<ul className="plan-list-wrapper">
|
<ul className="plan-list-wrapper">
|
||||||
{plans.map((plan) => {
|
{plans.map((plan) => {
|
||||||
return (
|
return (
|
||||||
<li key={plan.plan_id}>
|
<li key={plan.plan_id}>
|
||||||
<Plan plan={plan} />
|
<Plan plan={plan} savePlan={savePlan}/>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -18,6 +18,7 @@ function PlanList({ plans }) {
|
|||||||
|
|
||||||
PlanList.propTypes = {
|
PlanList.propTypes = {
|
||||||
plans: PropTypes.arrayOf(PropTypes.object),
|
plans: PropTypes.arrayOf(PropTypes.object),
|
||||||
|
savePlan: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PlanList;
|
export default PlanList;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from "react";
|
|||||||
import { useAuth, useClient } from "../context/AuthContext";
|
import { useAuth, useClient } from "../context/AuthContext";
|
||||||
import "./AuthenticatedApp.scss";
|
import "./AuthenticatedApp.scss";
|
||||||
import PlanList from "../components/PlanList";
|
import PlanList from "../components/PlanList";
|
||||||
import { getPlansFunc } from "../services/plans-service";
|
import { getPlansFunc, savePlanFunc } from "../services/plans-service";
|
||||||
|
|
||||||
function AuthenticatedApp() {
|
function AuthenticatedApp() {
|
||||||
const { logout, user } = useAuth();
|
const { logout, user } = useAuth();
|
||||||
@@ -14,6 +14,31 @@ function AuthenticatedApp() {
|
|||||||
// const getPlans = getPlansFunc(client);
|
// const getPlans = getPlansFunc(client);
|
||||||
|
|
||||||
const getPlans = useCallback(() => getPlansFunc(client)(), [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(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -40,7 +65,7 @@ function AuthenticatedApp() {
|
|||||||
</p>
|
</p>
|
||||||
<p>Error: {error || "No errors"}</p>
|
<p>Error: {error || "No errors"}</p>
|
||||||
<p>Loading: {isLoading ? "Loading" : "Not loading"}</p>
|
<p>Loading: {isLoading ? "Loading" : "Not loading"}</p>
|
||||||
<PlanList plans={plans} />
|
<PlanList plans={plans} savePlan={updatePlan} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user