text: (this.webpackJsonpclient=this.webpackJsonpclient||[]).push([[0],{27:function(e,t,a){},28:function(e,t,a){},36:function(e,t,a){"use strict";a.r(t);var n=a(1),c=a.n(n),s=a(15),r=a.n(s),o=(a(27),a(2)),l=(a.p,a(28),a(16)),i=a(3),u=a(17),b=a.n(u),j=a(21),d=(a(8),a(0));var h=function(e){return Object(d.jsxs)("div",{className:"card mb-3 "+(e.bgcolor?" bg-"+e.bgcolor:" ")+(e.txtcolor?" text-"+e.txtcolor:" text-white"),style:{maxWidth:"18rem"},children:[Object(d.jsx)("div",{className:"card-header",children:Object(d.jsxs)("div",{className:"container",children:[Object(d.jsxs)("div",{className:"row",children:[Object(d.jsx)("div",{className:"col-7",children:Object(d.jsx)("div",{className:"text-left",style:{fontSize:"16px"},children:e.header})}),Object(d.jsx)("div",{className:"col-5",children:Object(d.jsx)("div",{className:"text-right",style:{fontSize:"12px"},children:"Username:"})})]}),Object(d.jsx)("div",{className:"row",children:Object(d.jsx)("div",{className:"col-12",children:Object(d.jsx)("div",{className:"text-right",style:{fontSize:"12px"},children:e.useraccount})})})]})}),Object(d.jsxs)("div",{className:"card-body",children:[e.title&&Object(d.jsx)("h5",{className:"card-title",children:e.title}),e.text&&Object(d.jsx)("p",{className:"card-text",children:e.text}),e.body,e.status&&Object(d.jsx)("div",{id:"createStatus",children:e.status})]})]})};var O=function(){var e=c.a.useContext(A),t=e.state,a=e.dispatch,n=c.a.useState(!0),s=Object(o.a)(n,2),r=s[0],l=s[1],i=c.a.useState(""),u=Object(o.a)(i,2),O=u[0],m=u[1],g=c.a.useState(""),p=Object(o.a)(g,2),x=p[0],f=p[1],v=c.a.useState(""),N=Object(o.a)(v,2),S=N[0],y=N[1],w=c.a.useState(""),E=Object(o.a)(w,2),C=E[0],L=E[1],k=c.a.useState(""),T=Object(o.a)(k,2),J=T[0],U=T[1],F=c.a.useState(0),B=Object(o.a)(F,2),D=B[0],P=(B[1],c.a.useState(!1)),R=Object(o.a)(P,2),W=R[0],_=R[1],I=c.a.useState(!1),G=Object(o.a)(I,2),M=G[0];function z(e,t){return e?!(e===J&&J.length<8)||(m("Error: password must be at least 8 characters long"),alert("Error: password must be at least 8 characters long"),setTimeout((function(){return m("")}),3e3),!1):(m("Error: "+t),alert("Error: "+t),setTimeout((function(){return m("")}),3e3),!1)}return G[1],c.a.useEffect((function(){W?(l(!1),m(t.email+" is logged in")):l(!0)})),Object(d.jsx)(h,{bgcolor:"primary",header:"Create Account",status:O,body:r?Object(d.jsxs)(d.Fragment,{children:["Name",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",id:"name",placeholder:"Enter name",value:S,onChange:function(e){return y(e.currentTarget.value)}}),Object(d.jsx)("br",{}),"Email address",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",id:"email",placeholder:"Enter email",value:C,onChange:function(e){return L(e.currentTarget.value)}}),Object(d.jsx)("br",{}),"Password",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"password",className:"form-control",id:"password",placeholder:"Enter password",value:J,onChange:function(e){return U(e.currentTarget.value)}}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",disabled:!S&&!C&&!J,onClick:function(){if(z(S,"name")&&z(C,"email")&&z(J,"password")){console.log(S,C,J);var e="/account/create/".concat(S,"/").concat(C,"/").concat(J);Object(j.a)(b.a.mark((function t(){var a,n;return b.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(e);case 2:return a=t.sent,t.next=5,a.json();case 5:n=t.sent,console.log(n);case 7:case"end":return t.stop()}}),t)})))(),_(!0),f("Success!"),l(!1),a({type:"CREATE_USER",payload:{newUser:{name:S,email:C,password:J,balance:D,isLogin:W,isAuth:M}}})}},children:"Create Account"})]}):Object(d.jsx)(d.Fragment,{children:Object(d.jsx)("h5",{children:x})}),useraccount:t.email})};var m=function(){var e=c.a.useContext(A),t=e.state,a=e.dispatch,n=c.a.useState(!0),s=Object(o.a)(n,2),r=s[0],l=s[1],i=c.a.useState(""),u=Object(o.a)(i,2),b=u[0],j=u[1],O=c.a.useState(!1),m=Object(o.a)(O,2),g=m[0],p=m[1],x=c.a.useState(""),f=Object(o.a)(x,2),v=f[0],N=(f[1],c.a.useState(0)),S=Object(o.a)(N,2),y=S[0],w=S[1],E=c.a.useState(0),C=Object(o.a)(E,2),L=C[0],k=C[1],T=t.isLogin,J=t.isAuth,U=t.email,F=t.password;return console.log("state object:"+JSON.stringify(t)),c.a.useEffect((function(){fetch("/account/login/".concat(U,"/").concat(F)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);k(t.balance),console.log("JSON:",t),console.log(t.balance)}catch(a){console.log("err:",e)}})),console.log("Use Effect "+U)})),console.log("UseEffect state object: "+JSON.stringify(t)),Object(d.jsx)(h,{bgcolor:"primary",header:"Deposit",body:r?Object(d.jsxs)(d.Fragment,{children:[Object(d.jsxs)("h5",{children:["Current Balance: ",L]}),Object(d.jsx)("br",{}),"Amount",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",id:"amount",placeholder:"Enter amount",value:y,onChange:function(e){return w(e.currentTarget.value)}}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",disabled:!y,onClick:function(){fetch("/account/update/".concat(U,"/").concat(y)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);j(""),p(!0),console.log("JSON:",t)}catch(a){j("Deposit failed"),console.log("err:",e)}})),a({type:"UPDATE_BALANCE",payload:{userDeposit:{name:v,email:U,password:F,amount:y,balance:L,isLogin:T,isAuth:J}}}),w(0),console.log("After Deposit "+U),console.log("After deposit state: "+t.balance),l(!0)},children:"Deposit"})]}):Object(d.jsx)(d.Fragment,{children:Object(d.jsx)("h5",{children:g})}),useraccount:U,status:b})};var g=function(){var e=c.a.useContext(A),t=e.state,a=e.dispatch,n=c.a.useState(!0),s=Object(o.a)(n,2),r=s[0],l=s[1],i=c.a.useState(""),u=Object(o.a)(i,2),b=u[0],j=u[1],O=c.a.useState(!1),m=Object(o.a)(O,2),g=m[0],p=m[1],x=c.a.useState(""),f=Object(o.a)(x,2),v=f[0],N=(f[1],c.a.useState(0)),S=Object(o.a)(N,2),y=S[0],w=S[1],E=c.a.useState(0),C=Object(o.a)(E,2),L=C[0],k=C[1],T=t.isLogin,J=t.isAuth,U=t.email,F=t.password;return console.log("state object:"+JSON.stringify(t)),c.a.useEffect((function(){fetch("/account/login/".concat(U,"/").concat(F)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);k(t.balance),console.log("JSON:",t),console.log(t.balance)}catch(a){console.log("err:",e)}})),console.log("Use Effect "+U)})),console.log("UseEffect state object: "+JSON.stringify(t)),Object(d.jsx)(h,{bgcolor:"primary",header:"Withdraw",body:r?Object(d.jsxs)(d.Fragment,{children:[Object(d.jsxs)("h5",{children:["Current Balance: ",L]}),Object(d.jsx)("br",{}),"Amount",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",id:"amount",placeholder:"Enter amount",value:y,onChange:function(e){return w(e.currentTarget.value)}}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",disabled:!y,onClick:function(){fetch("/account/update/".concat(U,"/").concat(-y)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);j(""),p(!0),console.log("JSON:",t)}catch(a){j("Withdraw failed"),console.log("err:",e)}})),a({type:"UPDATE_BALANCE",payload:{userDeposit:{name:v,email:U,password:F,amount:y,balance:L,isLogin:T,isAuth:J}}}),w(0),console.log("After Withdraw "+U),console.log("After withdraw state: "+t.balance),l(!0)},children:"Withdraw"})]}):Object(d.jsx)(d.Fragment,{children:Object(d.jsx)("h5",{children:g})}),useraccount:U,status:b})};var p=function(){var e=c.a.useState(""),t=Object(o.a)(e,2),a=t[0],n=t[1];return c.a.useEffect((function(){fetch("/account/all").then((function(e){return e.json()})).then((function(e){console.log(e),n(JSON.stringify(e))}))}),[]),Object(d.jsxs)(d.Fragment,{children:[Object(d.jsx)("h5",{children:"All Data in Store:"}),a]})};var x=function(){return Object(d.jsxs)("nav",{className:"navbar navbar-expand-lg navbar-light bg-light",children:[Object(d.jsx)("a",{className:"navbar-brand","data-bs-toggle":"tooltip","data-bs-placement":"bottom",title:"Bank Home Page",href:"#/",children:"TaylorBank"}),Object(d.jsx)("button",{className:"navbar-toggler",type:"button","data-toggle":"collapse","data-target":"#navbarNav","aria-controls":"navbarNav","aria-expanded":"false","aria-label":"Toggle navigation",children:Object(d.jsx)("span",{className:"navbar-toggler-icon"})}),Object(d.jsx)("div",{className:"collapse navbar-collapse",id:"navbarNav",children:Object(d.jsxs)("ul",{className:"navbar-nav",children:[Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link","aria-current":"page","data-bs-toggle":"tooltip","data-bs-placement":"bottom",title:"Create an Account",href:"#/CreateAccount/",children:"Create Account"})}),Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link",href:"#/login/",children:"Login"})}),Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link",href:"#/logout/",children:"Logout"})}),Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link","aria-current":"page","data-bs-toggle":"tooltip","data-bs-placement":"bottom",title:"Make a Deposit",href:"#/deposit/",children:"Deposit"})}),Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link","aria-current":"page","data-bs-toggle":"tooltip","data-bs-placement":"bottom",title:"Make a Withdrawl",href:"#/withdraw/",children:"Withdraw"})}),Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link",href:"#/balance/",children:"Balance"})}),Object(d.jsx)("li",{className:"nav-item",children:Object(d.jsx)("a",{className:"nav-link",href:"#/alldata/",children:"AllData"})})]})})]})};var f=function(e){return Object(d.jsxs)("div",{className:"card mb-3 "+(e.bgcolor?" bg-"+e.bgcolor:" ")+(e.txtcolor?" text-"+e.txtcolor:" text-white"),style:{maxWidth:"18rem"},children:[Object(d.jsx)("div",{className:"card-header",children:e.header}),Object(d.jsxs)("div",{className:"card-body",children:[e.title&&Object(d.jsx)("h5",{className:"card-title",children:e.title}),e.text&&Object(d.jsx)("p",{className:"card-text",children:e.text}),e.body," ",Object(d.jsx)("br",{}),e.status&&Object(d.jsx)("div",{id:"createStatus",children:e.status})]})]})};var v=function(){return Object(d.jsx)(f,{txtcolor:"black",header:"BadBank Landing Module",title:"Welcome to TaylorBank",text:"You can move around using the navigation bar.",body:Object(d.jsx)("img",{src:"bank.png",className:"img-fluid",alt:"Responsive image"})})};var N=function(){var e=c.a.useContext(A),t=e.state,a=e.dispatch,n=c.a.useState(!0),s=Object(o.a)(n,2),r=s[0],l=s[1],i=c.a.useState(""),u=Object(o.a)(i,2),b=u[0],j=u[1],O=c.a.useState(""),m=Object(o.a)(O,2),g=(m[0],m[1],c.a.useState("")),p=Object(o.a)(g,2),x=p[0],f=p[1],v=c.a.useState(""),N=Object(o.a)(v,2),S=N[0],y=N[1],w=c.a.useState(""),E=Object(o.a)(w,2),C=E[0],L=E[1],k=c.a.useState(0),T=Object(o.a)(k,2),J=T[0],U=T[1],F=c.a.useState(!1),B=Object(o.a)(F,2),D=B[0],P=B[1],R=c.a.useState(!1),W=Object(o.a)(R,2),_=W[0],I=W[1];function G(e,t){return!!e||(j("Error: "+t),alert("Error: "+t),setTimeout((function(){return j("")}),3e3),!1)}function M(){var e={name:x,email:S,password:C,balance:J,isLogin:D,isAuth:_};console.log("update: "+J),a({type:"LOGIN_USER",payload:{loginUser:e}})}return c.a.useEffect((function(){D?(l(!1),j(t.email+" is logged in")):(y(""),l(!0))}),[]),Object(d.jsx)(h,{bgcolor:"primary",header:"Login",status:b,body:r?Object(d.jsxs)(d.Fragment,{children:["Email address",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",id:"email",placeholder:"Enter email",value:S,onChange:function(e){return y(e.currentTarget.value)}}),Object(d.jsx)("br",{}),"Password",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"password",className:"form-control",id:"password",placeholder:"Enter password",value:C,onChange:function(e){return L(e.currentTarget.value)}}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",disabled:!S&&!C,onClick:function(){G(S,"email")&&G(C,"password")&&(fetch("/account/login/".concat(S,"/").concat(C)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);j(""),l(!1),P(!0),U(t.balance),console.log("JSON:",t),console.log(t.balance)}catch(a){j(e),l(!0),L(""),console.log("err:",e)}})),M())},children:"Login"})]}):Object(d.jsxs)(d.Fragment,{children:[Object(d.jsxs)("h5",{children:["Current Balance: ",J]}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",disabled:!D,onClick:function(){fetch("/account/login/".concat(S,"/").concat(C)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);j(""),l(!0),P(!1),U(t.balance),f(""),y(""),L(""),U(0),I(!1),console.log("JSON:",t),console.log(t.balance)}catch(a){j(e),l(!0),L(""),console.log("err:",e)}})),M()},children:"Logout"})]}),useraccount:S})};var S=function(){var e=c.a.useContext(A),t=e.state,a=e.dispatch,n=c.a.useState(!0),s=Object(o.a)(n,2),r=s[0],l=s[1],i=c.a.useState(""),u=Object(o.a)(i,2),b=u[0],j=u[1],O=c.a.useState(""),m=Object(o.a)(O,2),g=(m[0],m[1],c.a.useState("")),p=Object(o.a)(g,2),x=p[0],f=p[1],v=c.a.useState(""),N=Object(o.a)(v,2),S=N[0],y=N[1],w=c.a.useState(""),E=Object(o.a)(w,2),C=E[0],L=E[1],k=c.a.useState(0),T=Object(o.a)(k,2),J=T[0],U=T[1],F=c.a.useState(!1),B=Object(o.a)(F,2),D=B[0],P=B[1],R=c.a.useState(!1),W=Object(o.a)(R,2),_=W[0],I=W[1];function G(e,t){return!!e||(j("Error: "+t),alert("Error: "+t),setTimeout((function(){return j("")}),3e3),!1)}return c.a.useEffect((function(){D?(l(!1),j(t.email+" is logged in")):(y(""),l(!0))}),[]),Object(d.jsx)(h,{bgcolor:"primary",header:"Logout",status:b,body:r?Object(d.jsxs)(d.Fragment,{children:["Email address",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",id:"email",placeholder:"Enter email",value:S,onChange:function(e){return y(e.currentTarget.value)}}),Object(d.jsx)("br",{}),"Password",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"password",className:"form-control",id:"password",placeholder:"Enter password",value:C,onChange:function(e){return L(e.currentTarget.value)}}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",disabled:!S&&!C,onClick:function(){G(S,"email")&&G(C,"password")&&(fetch("/account/login/".concat(S,"/").concat(C)).then((function(e){return e.text()})).then((function(e){try{var t=JSON.parse(e);j(""),l(!0),P(!1),U(t.balance),f(""),y(""),L(""),U(0),I(!1),console.log("JSON:",t),console.log(t.balance)}catch(a){j(e),l(!0),L(""),console.log("err:",e)}})),D?l(!0):(l(!1),j(t.email+" is logged out")),function(){var e={name:x,email:S,password:C,balance:J,isLogin:D,isAuth:_};console.log("update: "+J),a({type:"LOGIN_USER",payload:{loginUser:e}})}())},children:"Logout"})]}):Object(d.jsx)(d.Fragment,{children:Object(d.jsx)("h5",{children:"Logged Out"})}),useraccount:S})};function y(e){return Object(d.jsxs)(d.Fragment,{children:[Object(d.jsx)("h5",{children:"Success "}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",onClick:function(){e.setShow(!0),e.setStatus("")},children:"Check balance again"})]})}function w(e){var t=c.a.useState(""),a=Object(o.a)(t,2),n=a[0],s=a[1],r=c.a.useState(""),l=Object(o.a)(r,2);l[0],l[1];return Object(d.jsxs)(d.Fragment,{children:["Email",Object(d.jsx)("br",{}),Object(d.jsx)("input",{type:"input",className:"form-control",placeholder:"Enter email",value:n,onChange:function(e){return s(e.currentTarget.value)}}),Object(d.jsx)("br",{}),Object(d.jsx)("button",{type:"submit",className:"btn btn-light",onClick:function(){fetch("/account/findOne/".concat(n)).then((function(e){return e.text()})).then((function(t){try{var a=JSON.parse(t);e.setStatus(t),e.setShow(!1),console.log("JSON:",a)}catch(n){e.setStatus(t),console.log("err:",t)}}))},children:"Check Balance"})]})}var E=function(){var e=c.a.useContext(A),t=e.state,a=(e.dispatch,c.a.useState(!0)),n=Object(o.a)(a,2),s=n[0],r=n[1],l=c.a.useState(""),i=Object(o.a)(l,2),u=i[0],b=i[1];return Object(d.jsx)(h,{bgcolor:"info",header:"Balance",useraccount:t.name,status:u,body:s?Object(d.jsx)(w,{setShow:r,setStatus:b}):Object(d.jsx)(y,{setShow:r,setStatus:b})})};var C=function(e,t){switch(t.type){case"CREATE_USER":var a=t.payload.newUser;return{name:a.name,email:a.email,password:a.password,balance:a.balance,isLogin:a.isLogin,isAuth:a.isAuth};case"LOGIN_USER":var n=t.payload.loginUser;return{name:n.name,email:n.email,password:n.password,balance:n.balance,isLogin:!0,isAuth:n.isAuth};case"LOGOUT_USER":t.payload.logoutUser;return{name:"",email:"",password:"",balance:0,isLogin:!1,isAuth:!1};case"UPDATE_BALANCE":var c=t.payload.userDeposit;return{name:c.name,email:c.email,password:c.password,balance:c.balance+c.amount,isLogin:c.isLogin,isAuth:c.isAuth};default:return e}},A=c.a.createContext({name:"",email:"",password:"",balance:0,isLogin:!1,isAuth:!1});var L=function(){var e=c.a.useContext(A),t=c.a.useReducer(C,e),a=Object(o.a)(t,2),n=a[0],s=a[1];return Object(d.jsxs)(l.a,{children:[Object(d.jsx)(x,{}),Object(d.jsx)(A.Provider,{value:{state:n,dispatch:s},children:Object(d.jsxs)("div",{className:"container",style:{padding:"20px"},children:[Object(d.jsx)(i.a,{path:"/",exact:!0,component:v}),Object(d.jsx)(i.a,{path:"/createaccount/",component:O}),Object(d.jsx)(i.a,{path:"/login/",component:N}),Object(d.jsx)(i.a,{path:"/logout/",component:S}),Object(d.jsx)(i.a,{path:"/deposit/",component:m}),Object(d.jsx)(i.a,{path:"/withdraw/",component:g}),Object(d.jsx)(i.a,{path:"/balance/",component:E}),Object(d.jsx)(i.a,{path:"/alldata/",component:p})]})})]})},k=function(e){e&&e instanceof Function&&a.e(3).then(a.bind(null,39)).then((function(t){var a=t.getCLS,n=t.getFID,c=t.getFCP,s=t.getLCP,r=t.getTTFB;a(e),n(e),c(e),s(e),r(e)}))};r.a.render(Object(d.jsx)(c.a.StrictMode,{children:Object(d.jsx)(L,{})}),document.getElementById("root")),k()}},[[36,1,2]]]);
  //# sourceMappingURL=main.1d51acd1.chunk.js.map