diff --git a/assets/index-bcf11e5e.js b/assets/index-d3b424a8.js similarity index 99% rename from assets/index-bcf11e5e.js rename to assets/index-d3b424a8.js index 7b4ce8d..8c935d0 100644 --- a/assets/index-bcf11e5e.js +++ b/assets/index-d3b424a8.js @@ -784,4 +784,4 @@ Content-Type: `+u.contentType+`\r * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */kr(Q3,Y3,"app");const Z3={apiKey:"AIzaSyDJ_d4weAMvgEzNu1WbSfE4DiOG7wFE66A",authDomain:"rateio-facil-uploads.firebaseapp.com",projectId:"rateio-facil-uploads",storageBucket:"rateio-facil-uploads.appspot.com",messagingSenderId:"438785028187",appId:"1:438785028187:web:612dd65e8c46710547cf7e",measurementId:"G-3BW2VEHBTZ"},J3=Uv(Z3),e6=V3(J3);function t6(){const[e,t]=E.useState(""),[n,r]=E.useState(0),{user:o}=E.useContext(qe),{addImg:i}=E.useContext(ft),s=1e3;return{handleUpload:l=>{if(l){const u=q3(e6,`images/${o.username}/${l.name}`),c=H3(u,l);c.on("state_changed",h=>{const f=h.bytesTransferred/h.totalBytes*100;r(f)},h=>{alert(h)},async()=>{try{const h=await W3(c.snapshot.ref);t(h),setTimeout(async()=>{await i(h)},s)}catch(h){alert(h)}})}},imageUrl:e,progress:n}}function n6(e){return Et({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}},{tag:"path",attr:{d:"M15 3a2 2 0 0 1 1.995 1.85l.005 .15a1 1 0 0 0 .883 .993l.117 .007h1a3 3 0 0 1 2.995 2.824l.005 .176v9a3 3 0 0 1 -2.824 2.995l-.176 .005h-14a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-9a3 3 0 0 1 2.824 -2.995l.176 -.005h1a1 1 0 0 0 1 -1a2 2 0 0 1 1.85 -1.995l.15 -.005h6zm-3 7a3 3 0 0 0 -2.985 2.698l-.011 .152l-.004 .15l.004 .15a3 3 0 1 0 2.996 -3.15z",strokeWidth:"0",fill:"currentColor"}}]})(e)}function r6(e){return Et({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"}},{tag:"path",attr:{d:"M16 7h-1l-1-1h-4L9 7H8c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2zm-4 7c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z"}},{tag:"path",attr:{d:"M8.57.51l4.48 4.48V2.04c4.72.47 8.48 4.23 8.95 8.95h2C23.34 3.02 15.49-1.59 8.57.51zM10.95 21.96c-4.72-.47-8.48-4.23-8.95-8.95H0c.66 7.97 8.51 12.58 15.43 10.48l-4.48-4.48v2.95z"}}]})(e)}const o6="_container_m2e72_1",i6="_camera_m2e72_10",s6="_snaptBtn_m2e72_16",a6="_result_m2e72_22",l6="_buttons_m2e72_30",u6="_snapBtn_m2e72_40",c6="_backBtn_m2e72_66",f6="_switchBtn_m2e72_88",or={container:o6,camera:i6,snaptBtn:s6,result:a6,buttons:l6,snapBtn:u6,backBtn:c6,switchBtn:f6};function ux({setOpenCamera:e,setCurrentImage:t}){const n=E.useRef(null),[r,o]=E.useState(!1),i=()=>{navigator.mediaDevices.getUserMedia({video:{width:2160,height:3840,facingMode:r?"user":"environment"}}).then(a=>{const l=n.current;l.srcObject=a,l.play()}).catch(a=>{console.log(a)})},s=()=>{const a=n.current,l=document.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight,l.getContext("2d").drawImage(a,0,0,l.width,l.height),l.toBlob(c=>{const h=new File([c],"foto.png",{type:"image/png"});t(h)},"image/png"),e(!1)};return E.useEffect(()=>{i()},[n.current]),_.jsxs("div",{className:or.container,children:[_.jsx(tm,{className:or.backBtn,onClick:()=>e(!1)}),_.jsx("video",{className:or.camera,ref:n,children:_.jsx("track",{kind:"captions"})}),_.jsxs("section",{className:or.buttons,children:[_.jsx("button",{type:"button",onClick:s,"aria-label":"Tirar Foto",className:or.snapBtn,children:_.jsx(n6,{})}),_.jsx("button",{type:"button",onClick:()=>o(!r),"aria-label":"Trocar Câmera",className:or.switchBtn,children:_.jsx(r6,{})})]})]})}ux.propTypes={setOpenCamera:F.func.isRequired,setCurrentImage:F.func.isRequired};function cx({setTakePhoto:e}){const[t,n]=E.useState(""),[r,o]=E.useState(null),[i,s]=E.useState(!0),[a,l]=E.useState(!1),[u,c]=E.useState(null),{handleUpload:h,imageUrl:f}=t6();E.useEffect(()=>{s(!r)},[r]);const v=w=>{if(w){const g=URL.createObjectURL(w);o(g),n(w.name),c(w)}},p=w=>{const g=w.target.files[0];v(g)},x=()=>{h(u),e(!1)};return E.useEffect(()=>{v(u)},[u]),_.jsx("main",{className:sh.container,children:_.jsxs(bn,{onSubmit:x,children:[_.jsx(Bv,{handleFileInputChange:p,text:r?"Alterar imagem":"Adicionar imagem"}),_.jsx(fe,{type:"button",onClick:()=>l(!0),children:"Tirar Foto "}),a&&_.jsx(ux,{setOpenCamera:l,setCurrentImage:c}),f.length===0&&r&&_.jsxs("div",{children:[_.jsx("img",{src:r,alt:"Imagem",width:"200px"}),_.jsx("p",{children:t})]}),_.jsxs("section",{className:sh.buttons,children:[_.jsx(fe,{type:"submit",disabled:i,children:"Enviar"}),_.jsx(fe,{type:"reset",onClick:()=>e(!1),children:"cancelar"})]})]})})}cx.propTypes={setTakePhoto:F.func.isRequired};function d6(){const[e,t]=E.useState([]),{orders:n,getOrders:r,finishBill:o,loading:i}=E.useContext(ft),[s,a]=E.useState(0),[l,u]=E.useState([]),[c,h]=E.useState(!1),[f,v]=E.useState(!1),p=Ot(),{pathname:x}=ct(),{getFriendsName:w}=Ys(),g=()=>{u([...l,e[s]])},d=async()=>{await o(x.split("/")[3]),p("/home")};if(E.useEffect(()=>{t([]),a(0),u([]),h(!1),r(x.split("/")[3])},[x]),E.useEffect(()=>{t([...w(n)])},[n]),E.useEffect(()=>{setTimeout(()=>{l.length===e.length&&e.length!==0?h(!0):h(!1)},100)},[l]),e.length===0&&i)return _.jsx(Tn,{});const m=y=>{y>=0&&ym(s-1)}),_.jsx(Fa.Next,{className:Nn.pageButton,onClick:()=>m(s+1)})]}),c&&_.jsx("main",{className:Nn.finishButton,children:_.jsxs("div",{children:[_.jsx("h2",{children:"Conta paga!"}),_.jsx("span",{children:"Os valores podem estar diferentes, confira!"}),!f&&_.jsxs("p",{children:["Deseja registrar este momento com uma foto?",_.jsx("button",{className:Nn.takePhotoBtn,type:"button",onClick:()=>v(!0),children:"clique aqui"})]}),f&&_.jsx(cx,{setTakePhoto:v}),_.jsx(fe,{className:Nn.finishButton,type:"button",onClick:d,children:"Finalizar"})]})})]})}const h6="_container_1o3rd_1",Eh={container:h6},p6="_card_1fz7x_1",m6={card:p6};function m0({calculation:e}){if(e){const{establishment:t,value:n,taxService:r,total:o}=e;return _.jsxs("div",{className:m6.card,children:[_.jsxs("ul",{children:[_.jsxs("li",{children:[_.jsx("strong",{children:"Estabelcimento:"}),_.jsx("p",{children:t})]}),_.jsxs("li",{children:[_.jsx("strong",{children:"Valor:"}),_.jsx("p",{children:`R$ ${n}`})]}),_.jsxs("li",{children:[_.jsx("strong",{children:"Taxa de Serviço:"}),_.jsx("p",{children:`R$ ${r}`})]}),_.jsxs("li",{children:[_.jsx("strong",{children:"Total:"}),_.jsx("p",{children:`R$ ${o}`})]})]}),_.jsx("span",{children:"confira os valores com o garçom!"})]})}}m0.propTypes={calculation:F.shape({establishment:F.string,value:F.number,taxService:F.number,total:F.number})};m0.defaultProps={calculation:{establishment:"",value:0,taxService:0,total:0}};function fx(){const{getCalculation:e,calculation:t,loading:n}=E.useContext(ft),[r,o]=E.useState(!1),{pathname:i}=ct(),s=Ot();return E.useEffect(()=>{const a=i.split("/")[3];e(a)},[]),n?_.jsx(Tn,{}):_.jsxs("main",{className:Eh.container,children:[_.jsx(ia,{}),_.jsx("h1",{className:Eh.title,children:"Sua conta!"}),_.jsx(m0,{calculation:t}),_.jsx(Wn,{text:"esta correto?",onChange:()=>o(!r),checked:r}),_.jsx(fe,{onClick:()=>s(`/${t.userId}/bill/${t.billId}/pagamento`),disabled:!r,children:"Pagar"})]})}fx.propTypes={}.isRequired;function v6(){const{error:e}=E.useContext(qe),{error:t}=E.useContext(ft);return _.jsxs("div",{children:[_.jsx("h1",{children:"Página não encontrada"}),_.jsx("p",{children:e||t}),_.jsx(Cr,{to:"/home",children:"Voltar para a página inicial"})]})}const x6="_container_g7fvz_1",g6={container:x6};function y6(){const[e,t]=E.useState(!1),{confirmUser:n}=E.useContext(qe),r=ct();return E.useEffect(()=>{const o=r.search.split("=")[1];n(o).then(()=>t(!0))},[]),e?_.jsxs("main",{className:g6.container,children:[_.jsx("p",{children:"Sua conta foi confirmada com sucesso!"}),_.jsx(Cr,{to:"/",children:_.jsx("p",{children:"Ir para a página de login"})})]}):_.jsx(Tn,{})}function _6(){return _.jsx("main",{className:Y2.container,children:_.jsx(Pv,{children:_.jsxs(z2,{children:[_.jsx(nt,{path:":id/bill/:billId/pagamento",element:_.jsx(d6,{})}),_.jsx(nt,{path:"/:id/bill/:billId/calculo",element:_.jsx(fx,{})}),_.jsx(nt,{path:"/:id/bill/:billId",element:_.jsx(z8,{})}),_.jsx(nt,{path:"/bills",element:_.jsx(HE,{})}),_.jsx(nt,{path:"/perfil",element:_.jsx($E,{})}),_.jsx(nt,{path:"/home",element:_.jsx(F_,{})}),_.jsx(nt,{path:"/criarconta/confirmacao/mensagem",element:_.jsx(rm,{})}),_.jsx(nt,{path:"/confirmacao",element:_.jsx(y6,{})}),_.jsx(nt,{path:"/criar-conta",element:_.jsx(W_,{})}),_.jsx(nt,{path:"/404",element:_.jsx(v6,{})}),_.jsx(nt,{path:"/",element:_.jsx(R_,{})})]})})})}const w6={OK:200,CREATED:201,BAD_REQUEST:400,UNAUTHORIZED:401,NOT_FOUND:404,INTERNAL_SERVER_ERROR:500,SERVICE_UNAVAILABLE:503,FORBIDDEN:403};function dx({children:e}){const t={id:null,name:"",email:"",username:""},[n,r]=E.useState(null),[o,i]=E.useState(!1),[s,a]=E.useState(t),[l,u]=E.useState(""),[c,h]=E.useState(null),f={}.REACT_APP_API_URL.replace(/"/g,""),v=Ot(),{getToken:p}=uv(),x=1e3,w=async(R,k,P)=>{i(!0);try{const b=await Rt.post(`${f}/auth/login`,{username:R,password:k,remember:P}),T=b.data.data.token,A=b.data.data.user;r(T),a(A);const j=Vd(T),H=Vd(A.id);Gf("id",H),Gf("token",j),h("Login realizado com sucesso!"),u(null),v("/home")}catch(b){h(null),Gi(b,u,v)}},g=async()=>{i(!0);const R=p(),k=$t("id"),P=un(k);n||r(R);try{const b={headers:{Authorization:`Bearer ${R}`}},T=await Rt.get(`${f}/users/${P}`,b);a(T.data),u(null)}catch{localStorage.clear(),u("Ocorreu um erro ao buscar o usuário")}finally{setTimeout(()=>{i(!1)},x)}},d=async R=>{i(!0),R={...R,role:"user"};try{const k=await Rt.post(`${f}/users`,R);h(k.data.message),v("/criarconta/confirmacao/mensagem",{state:{email:R.email,name:R.name}})}catch(k){h(null),Gi(k,u,v)}finally{setTimeout(()=>{i(!1)},x)}},m=async R=>{i(!0);const k=p(),P=$t("id"),b=un(P),T={...R,role:"user"};try{const A={headers:{Authorization:`Bearer ${k}`}},j=await Rt.put(`${f}/users/${b}`,T,A);a(j.data.data),u("Usuário atualizado com sucesso!"),v("/perfil")}catch(A){A.response.status===w6.FORBIDDEN?u("Usuário já cadastrado"):u("Ocorreu um erro ao atualizar o usuário")}finally{setTimeout(()=>{i(!1)},x)}},y=async R=>{try{const k={headers:{Authorization:`Bearer ${R}`}},P=await Rt.put(`${f}/users/confirmation`,{},k);h(P.data.message),u(null)}catch(k){h(null),Gi(k,u,v)}},C=()=>{i(!0),localStorage.clear(),v("/"),u(null),h(null),i(!1)},S=E.useMemo(()=>({login:w,loading:o,error:l,setLoading:i,setToken:r,user:s,setUser:a,getUser:g,setError:u,createUser:d,updateUser:m,sucess:c,logout:C,confirmUser:y}),[o,n,l,s,c]);return _.jsx(qe.Provider,{value:S,children:e})}dx.propTypes={children:F.node.isRequired};Il.createRoot(document.getElementById("root")).render(_.jsx(E.StrictMode,{children:_.jsx(q2,{children:_.jsx(dx,{children:_.jsx(_6,{})})})})); + */kr(Q3,Y3,"app");const Z3={apiKey:"AIzaSyDJ_d4weAMvgEzNu1WbSfE4DiOG7wFE66A",authDomain:"rateio-facil-uploads.firebaseapp.com",projectId:"rateio-facil-uploads",storageBucket:"rateio-facil-uploads.appspot.com",messagingSenderId:"438785028187",appId:"1:438785028187:web:612dd65e8c46710547cf7e",measurementId:"G-3BW2VEHBTZ"},J3=Uv(Z3),e6=V3(J3);function t6(){const[e,t]=E.useState(""),[n,r]=E.useState(0),{user:o}=E.useContext(qe),{addImg:i}=E.useContext(ft),s=1e3;return{handleUpload:l=>{if(l){const u=q3(e6,`images/${o.username}/${l.name}`),c=H3(u,l);c.on("state_changed",h=>{const f=h.bytesTransferred/h.totalBytes*100;r(f)},h=>{alert(h)},async()=>{try{const h=await W3(c.snapshot.ref);t(h),setTimeout(async()=>{await i(h)},s)}catch(h){alert(h)}})}},imageUrl:e,progress:n}}function n6(e){return Et({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}},{tag:"path",attr:{d:"M15 3a2 2 0 0 1 1.995 1.85l.005 .15a1 1 0 0 0 .883 .993l.117 .007h1a3 3 0 0 1 2.995 2.824l.005 .176v9a3 3 0 0 1 -2.824 2.995l-.176 .005h-14a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-9a3 3 0 0 1 2.824 -2.995l.176 -.005h1a1 1 0 0 0 1 -1a2 2 0 0 1 1.85 -1.995l.15 -.005h6zm-3 7a3 3 0 0 0 -2.985 2.698l-.011 .152l-.004 .15l.004 .15a3 3 0 1 0 2.996 -3.15z",strokeWidth:"0",fill:"currentColor"}}]})(e)}function r6(e){return Et({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"}},{tag:"path",attr:{d:"M16 7h-1l-1-1h-4L9 7H8c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2zm-4 7c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z"}},{tag:"path",attr:{d:"M8.57.51l4.48 4.48V2.04c4.72.47 8.48 4.23 8.95 8.95h2C23.34 3.02 15.49-1.59 8.57.51zM10.95 21.96c-4.72-.47-8.48-4.23-8.95-8.95H0c.66 7.97 8.51 12.58 15.43 10.48l-4.48-4.48v2.95z"}}]})(e)}const o6="_container_m2e72_1",i6="_camera_m2e72_10",s6="_snaptBtn_m2e72_16",a6="_result_m2e72_22",l6="_buttons_m2e72_30",u6="_snapBtn_m2e72_40",c6="_backBtn_m2e72_66",f6="_switchBtn_m2e72_88",or={container:o6,camera:i6,snaptBtn:s6,result:a6,buttons:l6,snapBtn:u6,backBtn:c6,switchBtn:f6};function ux({setOpenCamera:e,setCurrentImage:t}){const n=E.useRef(null),[r,o]=E.useState(!1),i=()=>{navigator.mediaDevices.getUserMedia({video:{width:3840,height:2160,facingMode:r?"user":"environment"}}).then(a=>{const l=n.current;l.srcObject=a,l.play()}).catch(a=>{console.log(a)})},s=()=>{const a=n.current,l=document.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight,l.getContext("2d").drawImage(a,0,0,l.width,l.height),l.toBlob(c=>{const h=new File([c],"foto.png",{type:"image/png"});t(h)},"image/png"),e(!1)};return E.useEffect(()=>{i()},[n.current]),_.jsxs("div",{className:or.container,children:[_.jsx(tm,{className:or.backBtn,onClick:()=>e(!1)}),_.jsx("video",{className:or.camera,ref:n,children:_.jsx("track",{kind:"captions"})}),_.jsxs("section",{className:or.buttons,children:[_.jsx("button",{type:"button",onClick:s,"aria-label":"Tirar Foto",className:or.snapBtn,children:_.jsx(n6,{})}),_.jsx("button",{type:"button",onClick:()=>o(!r),"aria-label":"Trocar Câmera",className:or.switchBtn,children:_.jsx(r6,{})})]})]})}ux.propTypes={setOpenCamera:F.func.isRequired,setCurrentImage:F.func.isRequired};function cx({setTakePhoto:e}){const[t,n]=E.useState(""),[r,o]=E.useState(null),[i,s]=E.useState(!0),[a,l]=E.useState(!1),[u,c]=E.useState(null),{handleUpload:h,imageUrl:f}=t6();E.useEffect(()=>{s(!r)},[r]);const v=w=>{if(w){const g=URL.createObjectURL(w);o(g),n(w.name),c(w)}},p=w=>{const g=w.target.files[0];v(g)},x=()=>{h(u),e(!1)};return E.useEffect(()=>{v(u)},[u]),_.jsx("main",{className:sh.container,children:_.jsxs(bn,{onSubmit:x,children:[_.jsx(Bv,{handleFileInputChange:p,text:r?"Alterar imagem":"Adicionar imagem"}),_.jsx(fe,{type:"button",onClick:()=>l(!0),children:"Tirar Foto "}),a&&_.jsx(ux,{setOpenCamera:l,setCurrentImage:c}),f.length===0&&r&&_.jsxs("div",{children:[_.jsx("img",{src:r,alt:"Imagem",width:"200px"}),_.jsx("p",{children:t})]}),_.jsxs("section",{className:sh.buttons,children:[_.jsx(fe,{type:"submit",disabled:i,children:"Enviar"}),_.jsx(fe,{type:"reset",onClick:()=>e(!1),children:"cancelar"})]})]})})}cx.propTypes={setTakePhoto:F.func.isRequired};function d6(){const[e,t]=E.useState([]),{orders:n,getOrders:r,finishBill:o,loading:i}=E.useContext(ft),[s,a]=E.useState(0),[l,u]=E.useState([]),[c,h]=E.useState(!1),[f,v]=E.useState(!1),p=Ot(),{pathname:x}=ct(),{getFriendsName:w}=Ys(),g=()=>{u([...l,e[s]])},d=async()=>{await o(x.split("/")[3]),p("/home")};if(E.useEffect(()=>{t([]),a(0),u([]),h(!1),r(x.split("/")[3])},[x]),E.useEffect(()=>{t([...w(n)])},[n]),E.useEffect(()=>{setTimeout(()=>{l.length===e.length&&e.length!==0?h(!0):h(!1)},100)},[l]),e.length===0&&i)return _.jsx(Tn,{});const m=y=>{y>=0&&ym(s-1)}),_.jsx(Fa.Next,{className:Nn.pageButton,onClick:()=>m(s+1)})]}),c&&_.jsx("main",{className:Nn.finishButton,children:_.jsxs("div",{children:[_.jsx("h2",{children:"Conta paga!"}),_.jsx("span",{children:"Os valores podem estar diferentes, confira!"}),!f&&_.jsxs("p",{children:["Deseja registrar este momento com uma foto?",_.jsx("button",{className:Nn.takePhotoBtn,type:"button",onClick:()=>v(!0),children:"clique aqui"})]}),f&&_.jsx(cx,{setTakePhoto:v}),_.jsx(fe,{className:Nn.finishButton,type:"button",onClick:d,children:"Finalizar"})]})})]})}const h6="_container_1o3rd_1",Eh={container:h6},p6="_card_1fz7x_1",m6={card:p6};function m0({calculation:e}){if(e){const{establishment:t,value:n,taxService:r,total:o}=e;return _.jsxs("div",{className:m6.card,children:[_.jsxs("ul",{children:[_.jsxs("li",{children:[_.jsx("strong",{children:"Estabelcimento:"}),_.jsx("p",{children:t})]}),_.jsxs("li",{children:[_.jsx("strong",{children:"Valor:"}),_.jsx("p",{children:`R$ ${n}`})]}),_.jsxs("li",{children:[_.jsx("strong",{children:"Taxa de Serviço:"}),_.jsx("p",{children:`R$ ${r}`})]}),_.jsxs("li",{children:[_.jsx("strong",{children:"Total:"}),_.jsx("p",{children:`R$ ${o}`})]})]}),_.jsx("span",{children:"confira os valores com o garçom!"})]})}}m0.propTypes={calculation:F.shape({establishment:F.string,value:F.number,taxService:F.number,total:F.number})};m0.defaultProps={calculation:{establishment:"",value:0,taxService:0,total:0}};function fx(){const{getCalculation:e,calculation:t,loading:n}=E.useContext(ft),[r,o]=E.useState(!1),{pathname:i}=ct(),s=Ot();return E.useEffect(()=>{const a=i.split("/")[3];e(a)},[]),n?_.jsx(Tn,{}):_.jsxs("main",{className:Eh.container,children:[_.jsx(ia,{}),_.jsx("h1",{className:Eh.title,children:"Sua conta!"}),_.jsx(m0,{calculation:t}),_.jsx(Wn,{text:"esta correto?",onChange:()=>o(!r),checked:r}),_.jsx(fe,{onClick:()=>s(`/${t.userId}/bill/${t.billId}/pagamento`),disabled:!r,children:"Pagar"})]})}fx.propTypes={}.isRequired;function v6(){const{error:e}=E.useContext(qe),{error:t}=E.useContext(ft);return _.jsxs("div",{children:[_.jsx("h1",{children:"Página não encontrada"}),_.jsx("p",{children:e||t}),_.jsx(Cr,{to:"/home",children:"Voltar para a página inicial"})]})}const x6="_container_g7fvz_1",g6={container:x6};function y6(){const[e,t]=E.useState(!1),{confirmUser:n}=E.useContext(qe),r=ct();return E.useEffect(()=>{const o=r.search.split("=")[1];n(o).then(()=>t(!0))},[]),e?_.jsxs("main",{className:g6.container,children:[_.jsx("p",{children:"Sua conta foi confirmada com sucesso!"}),_.jsx(Cr,{to:"/",children:_.jsx("p",{children:"Ir para a página de login"})})]}):_.jsx(Tn,{})}function _6(){return _.jsx("main",{className:Y2.container,children:_.jsx(Pv,{children:_.jsxs(z2,{children:[_.jsx(nt,{path:":id/bill/:billId/pagamento",element:_.jsx(d6,{})}),_.jsx(nt,{path:"/:id/bill/:billId/calculo",element:_.jsx(fx,{})}),_.jsx(nt,{path:"/:id/bill/:billId",element:_.jsx(z8,{})}),_.jsx(nt,{path:"/bills",element:_.jsx(HE,{})}),_.jsx(nt,{path:"/perfil",element:_.jsx($E,{})}),_.jsx(nt,{path:"/home",element:_.jsx(F_,{})}),_.jsx(nt,{path:"/criarconta/confirmacao/mensagem",element:_.jsx(rm,{})}),_.jsx(nt,{path:"/confirmacao",element:_.jsx(y6,{})}),_.jsx(nt,{path:"/criar-conta",element:_.jsx(W_,{})}),_.jsx(nt,{path:"/404",element:_.jsx(v6,{})}),_.jsx(nt,{path:"/",element:_.jsx(R_,{})})]})})})}const w6={OK:200,CREATED:201,BAD_REQUEST:400,UNAUTHORIZED:401,NOT_FOUND:404,INTERNAL_SERVER_ERROR:500,SERVICE_UNAVAILABLE:503,FORBIDDEN:403};function dx({children:e}){const t={id:null,name:"",email:"",username:""},[n,r]=E.useState(null),[o,i]=E.useState(!1),[s,a]=E.useState(t),[l,u]=E.useState(""),[c,h]=E.useState(null),f={}.REACT_APP_API_URL.replace(/"/g,""),v=Ot(),{getToken:p}=uv(),x=1e3,w=async(R,k,P)=>{i(!0);try{const b=await Rt.post(`${f}/auth/login`,{username:R,password:k,remember:P}),T=b.data.data.token,A=b.data.data.user;r(T),a(A);const j=Vd(T),H=Vd(A.id);Gf("id",H),Gf("token",j),h("Login realizado com sucesso!"),u(null),v("/home")}catch(b){h(null),Gi(b,u,v)}},g=async()=>{i(!0);const R=p(),k=$t("id"),P=un(k);n||r(R);try{const b={headers:{Authorization:`Bearer ${R}`}},T=await Rt.get(`${f}/users/${P}`,b);a(T.data),u(null)}catch{localStorage.clear(),u("Ocorreu um erro ao buscar o usuário")}finally{setTimeout(()=>{i(!1)},x)}},d=async R=>{i(!0),R={...R,role:"user"};try{const k=await Rt.post(`${f}/users`,R);h(k.data.message),v("/criarconta/confirmacao/mensagem",{state:{email:R.email,name:R.name}})}catch(k){h(null),Gi(k,u,v)}finally{setTimeout(()=>{i(!1)},x)}},m=async R=>{i(!0);const k=p(),P=$t("id"),b=un(P),T={...R,role:"user"};try{const A={headers:{Authorization:`Bearer ${k}`}},j=await Rt.put(`${f}/users/${b}`,T,A);a(j.data.data),u("Usuário atualizado com sucesso!"),v("/perfil")}catch(A){A.response.status===w6.FORBIDDEN?u("Usuário já cadastrado"):u("Ocorreu um erro ao atualizar o usuário")}finally{setTimeout(()=>{i(!1)},x)}},y=async R=>{try{const k={headers:{Authorization:`Bearer ${R}`}},P=await Rt.put(`${f}/users/confirmation`,{},k);h(P.data.message),u(null)}catch(k){h(null),Gi(k,u,v)}},C=()=>{i(!0),localStorage.clear(),v("/"),u(null),h(null),i(!1)},S=E.useMemo(()=>({login:w,loading:o,error:l,setLoading:i,setToken:r,user:s,setUser:a,getUser:g,setError:u,createUser:d,updateUser:m,sucess:c,logout:C,confirmUser:y}),[o,n,l,s,c]);return _.jsx(qe.Provider,{value:S,children:e})}dx.propTypes={children:F.node.isRequired};Il.createRoot(document.getElementById("root")).render(_.jsx(E.StrictMode,{children:_.jsx(q2,{children:_.jsx(dx,{children:_.jsx(_6,{})})})})); diff --git a/index.html b/index.html index cc32896..2247b91 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ Rateio Facil - +