diff --git a/media-store/app/src/components/Header.js b/media-store/app/src/components/Header.js index 266c1daf..495ef11b 100644 --- a/media-store/app/src/components/Header.js +++ b/media-store/app/src/components/Header.js @@ -24,7 +24,14 @@ const RELOAD_LOCATION_NUMBER = 0; const Header = () => { const history = useHistory(); const location = useLocation(); - const { user, invoicedItems, locale, setLocale, loading } = useAppState(); + const { + user, + invoicedItems, + setInvoicedItems, + locale, + setLocale, + loading, + } = useAppState(); const currentKey = [keys.find((key) => key === location.pathname)]; const haveInvoicedItems = !isEmpty(invoicedItems); const invoicedItemsLength = invoicedItems.length; @@ -48,7 +55,7 @@ const Header = () => { const onUserLogout = () => { emitter.emit("UPDATE_USER", undefined); - history.push("/"); + history.go(0); }; return ( diff --git a/media-store/app/src/pages/Login.js b/media-store/app/src/pages/Login.js index da856e84..a96de9d8 100644 --- a/media-store/app/src/pages/Login.js +++ b/media-store/app/src/pages/Login.js @@ -29,7 +29,6 @@ const Login = () => { const { handleError } = useErrors(); const onFinish = (values) => { - console.log("Validation Success:", values); setLoading(true); login({ email: values.email, password: values.password }) .then((response) => { diff --git a/media-store/app/src/pages/PersonPage.js b/media-store/app/src/pages/PersonPage.js index 40284c3a..102569d2 100644 --- a/media-store/app/src/pages/PersonPage.js +++ b/media-store/app/src/pages/PersonPage.js @@ -1,10 +1,9 @@ -import React, { useState, useMemo } from "react"; -import { Card, Button, message } from "antd"; -import { omit } from "lodash"; +import React, { useState } from "react"; +import { Form, Button, message, Input } from "antd"; +import { omit, map } from "lodash"; import { fetchPerson, confirmPerson } from "../api/calls"; import { useErrors } from "../hooks/useErrors"; import { useAppState } from "../hooks/useAppState"; -import { Editable } from "../components/Editable"; import { MESSAGE_TIMEOUT } from "../util/constants"; import { useAbortableEffect } from "../hooks/useAbortableEffect"; @@ -25,7 +24,7 @@ const PERSON_PROP = { const PersonPage = () => { const { setLoading } = useAppState(); const { handleError } = useErrors(); - const [initialPerson, setInitialPerson] = useState({}); + const [form] = Form.useForm(); const [person, setPerson] = useState({ lastName: "", firstName: "", @@ -47,7 +46,6 @@ const PersonPage = () => { .then(({ data: personData }) => { personData = omit(personData, "@odata.context", "ID"); if (!status.aborted) { - setInitialPerson(personData); setPerson(personData); } }) @@ -55,67 +53,58 @@ const PersonPage = () => { .finally(() => setLoading(false)); }, []); - const onConfirmChanges = () => { + const onConfirmChanges = (newPerson) => { setLoading(true); - confirmPerson(person) + confirmPerson(newPerson) .then(() => { - setInitialPerson(person); message.success("Person successfully updated", MESSAGE_TIMEOUT); }) .catch(handleError) .finally(() => setLoading(false)); }; - const isPersonChanged = useMemo(() => { - const keysOne = Object.keys(initialPerson); - const keysTwo = Object.keys(person); - if (keysOne.length !== keysTwo.length) { - return true; - } - for (let key of keysOne) { - if (initialPerson[key] !== person[key]) { - return true; - } - } + const personProperties = map(Object.keys(person), (currentKey) => ( + + + + )); - return false; - }, [person, initialPerson]); - - const personProperties = Object.keys(person).reduce((acc, currentKey) => { - if (currentKey === "email") { - return acc; - } - return acc.concat([ -
- {PERSON_PROP[currentKey]} - - setPerson({ ...person, [`${currentKey}`]: value }) - } - /> -
, - ]); - }, []); + console.log(person, "person"); return ( <> - - {personProperties} -
- Email: {person.email} -
- {isPersonChanged && ( - - )} -
+ + + + )} ); }; diff --git a/media-store/app/src/pages/manage-store/TrackForm.js b/media-store/app/src/pages/manage-store/TrackForm.js index bb16bbae..3724dc85 100644 --- a/media-store/app/src/pages/manage-store/TrackForm.js +++ b/media-store/app/src/pages/manage-store/TrackForm.js @@ -13,10 +13,6 @@ const REQUIRED = [ message: "This filed is required!", }, ]; -const PRICE_INPUT_RULE = { - pattern: /^(?:\d*\.\d\d)$/, - message: "Price should have precision 2 and dot separator!", -}; const getAlbums = function (value) { return fetchAlbumsByName(value, ALBUMS_LIMIT) diff --git a/media-store/srv/browse-invoices-service.js b/media-store/srv/browse-invoices-service.js index 53541642..0a65091c 100644 --- a/media-store/srv/browse-invoices-service.js +++ b/media-store/srv/browse-invoices-service.js @@ -23,6 +23,7 @@ module.exports = async function () { this.on("invoice", async (req) => { const { tracks } = req.data; + const trackIds = tracks.map(({ ID }) => ID); const customerId = req.user.attr.ID; const total = tracks.reduce( (acc, { unitPrice }) => acc + Number(unitPrice), @@ -32,14 +33,15 @@ module.exports = async function () { const transaction = await db.tx(req); + // getting last ids for new records let { ID: lastInvoiceId } = await transaction.run( SELECT.one(Invoices).columns("ID").orderBy({ ID: "desc" }) ); - let { ID: lastInvoiceItemId } = await transaction.run( SELECT.one(InvoiceItems).columns("ID").orderBy({ ID: "desc" }) ); + // creating invoice const { results: [{ lastID: invoiceID }], } = await transaction.run( @@ -48,6 +50,7 @@ module.exports = async function () { .values(++lastInvoiceId, customerId, total, utcNowDateTime) ); + // creating invoice items await transaction.run( INSERT.into(InvoiceItems) .columns("ID", "invoice_ID", "track_ID", "unitPrice") diff --git a/media-store/srv/user-service.js b/media-store/srv/user-service.js index 1fb37cce..ef9c38eb 100644 --- a/media-store/srv/user-service.js +++ b/media-store/srv/user-service.js @@ -4,7 +4,7 @@ const bcrypt = require("bcryptjs"); const { ACCESS_TOKEN_SECRET, REFRESH_TOKEN_SECRET } = cds.env; const ACCESS_TOKEN_EXP_IN = "10s"; -const REFRESH_TOKEN_EXPIRES_IN = "16s"; +const REFRESH_TOKEN_EXPIRES_IN = "30s"; const comparePasswords = async (password, hashedPassword) => { return new Promise((resolve, reject) =>