Opravy dle SonarLint - klient
This commit is contained in:
parent
e03ba45415
commit
c264f9921e
@ -100,11 +100,19 @@ body,
|
|||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table> :not(caption) .action-icon {
|
.table> :not(caption) {
|
||||||
color: rgb(0, 89, 255);
|
.action-icon {
|
||||||
cursor: pointer;
|
color: rgb(0, 89, 255);
|
||||||
margin-left: 10px;
|
cursor: pointer;
|
||||||
padding: 0;
|
margin-left: 10px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buyer-icon {
|
||||||
|
color: #dbba00;
|
||||||
|
margin-left: 10px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.table ul {
|
.table ul {
|
||||||
|
|||||||
@ -141,16 +141,6 @@ function App() {
|
|||||||
if (!auth?.login) {
|
if (!auth?.login) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO tohle občas náhodně nezafunguje, nutno přepsat, viz https://medium.com/@teh_builder/ref-objects-inside-useeffect-hooks-eb7c15198780
|
|
||||||
// TODO nutno opravit
|
|
||||||
// if (data?.choices && choiceRef.current) {
|
|
||||||
// for (let entry of Object.entries(data.choices)) {
|
|
||||||
// if (entry[1].includes(auth.login)) {
|
|
||||||
// const value = entry[0] as any as number; // TODO tohle je absurdní
|
|
||||||
// choiceRef.current.value = Object.values(Locations)[value];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}, [auth, auth?.login, data?.choices])
|
}, [auth, auth?.login, data?.choices])
|
||||||
|
|
||||||
// Reference na mojí objednávku
|
// Reference na mojí objednávku
|
||||||
@ -310,7 +300,7 @@ function App() {
|
|||||||
const handlePizzaChange = async (value: SelectedOptionValue | SelectedOptionValue[]) => {
|
const handlePizzaChange = async (value: SelectedOptionValue | SelectedOptionValue[]) => {
|
||||||
if (auth?.login && data?.pizzaList) {
|
if (auth?.login && data?.pizzaList) {
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
throw Error('Nepodporovaný typ hodnoty');
|
throw new TypeError('Nepodporovaný typ hodnoty: ' + typeof value);
|
||||||
}
|
}
|
||||||
const s = value.split('|');
|
const s = value.split('|');
|
||||||
const pizzaIndex = Number.parseInt(s[0]);
|
const pizzaIndex = Number.parseInt(s[0]);
|
||||||
@ -331,30 +321,6 @@ function App() {
|
|||||||
updatePizzaDayNote({ body: { note: pizzaPoznamkaRef.current?.value } });
|
updatePizzaDayNote({ body: { note: pizzaPoznamkaRef.current?.value } });
|
||||||
}
|
}
|
||||||
|
|
||||||
// const addToCart = async () => {
|
|
||||||
// TODO aktuálně nefunkční - nedokážeme poslat PHPSESSIONID cookie
|
|
||||||
// if (data?.pizzaDay?.orders) {
|
|
||||||
// for (const order of data?.pizzaDay?.orders) {
|
|
||||||
// for (const pizzaOrder of order.pizzaList) {
|
|
||||||
// const url = 'https://www.pizzachefie.cz/pridat.html';
|
|
||||||
// const payload = new URLSearchParams();
|
|
||||||
// payload.append('varId', pizzaOrder.varId.toString());
|
|
||||||
// await fetch(url, {
|
|
||||||
// method: "POST",
|
|
||||||
// mode: "no-cors",
|
|
||||||
// cache: "no-cache",
|
|
||||||
// credentials: "same-origin",
|
|
||||||
// headers: {
|
|
||||||
// 'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
// },
|
|
||||||
// body: payload,
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // TODO otevřít košík v nové záložce
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
const handleChangeDepartureTime = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
const handleChangeDepartureTime = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
if (foodChoiceList?.length && choiceRef.current?.value) {
|
if (foodChoiceList?.length && choiceRef.current?.value) {
|
||||||
await changeDepartureTime({ body: { time: event.target.value as DepartureTime, dayIndex } });
|
await changeDepartureTime({ body: { time: event.target.value as DepartureTime, dayIndex } });
|
||||||
@ -477,11 +443,10 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<Row className='food-tables'>
|
<Row className='food-tables'>
|
||||||
{/* TODO zjednodušit, stačí iterovat klíče typu Restaurant */}
|
{Object.keys(Restaurant).map(key => {
|
||||||
{food['SLADOVNICKA'] && renderFoodTable('SLADOVNICKA', food['SLADOVNICKA'])}
|
const locationKey = key as Restaurant;
|
||||||
{food['TECHTOWER'] && renderFoodTable('TECHTOWER', food['TECHTOWER'])}
|
return food[locationKey] && renderFoodTable(locationKey, food[locationKey]);
|
||||||
{food['ZASTAVKAUMICHALA'] && renderFoodTable('ZASTAVKAUMICHALA', food['ZASTAVKAUMICHALA'])}
|
})}
|
||||||
{food['SENKSERIKOVA'] && renderFoodTable('SENKSERIKOVA', food['SENKSERIKOVA'])}
|
|
||||||
</Row>
|
</Row>
|
||||||
<div className='content-wrapper'>
|
<div className='content-wrapper'>
|
||||||
<div className='content'>
|
<div className='content'>
|
||||||
@ -543,22 +508,22 @@ function App() {
|
|||||||
const isBuyer = userPayload?.isBuyer || false;
|
const isBuyer = userPayload?.isBuyer || false;
|
||||||
return <tr key={entry[0]}>
|
return <tr key={entry[0]}>
|
||||||
<td>
|
<td>
|
||||||
|
{/* TODO zrefaktorovat, oddělit řádek do samostatné komponenty (a akce možná zvlášť) */}
|
||||||
{trusted && <span className='trusted-icon' title='Uživatel ověřený doménovým přihlášením'>
|
{trusted && <span className='trusted-icon' title='Uživatel ověřený doménovým přihlášením'>
|
||||||
<FontAwesomeIcon icon={faCircleCheck} style={{ cursor: "help" }} />
|
<FontAwesomeIcon icon={faCircleCheck} style={{ cursor: "help" }} />
|
||||||
</span>}
|
</span>}
|
||||||
{login}
|
{login}
|
||||||
{userPayload.departureTime && <small> ({userPayload.departureTime})</small>}
|
{userPayload.departureTime && <small> ({userPayload.departureTime})</small>}
|
||||||
{userPayload.note && <span style={{ fontSize: 'small' }}> ({userPayload.note})</span>}
|
{userPayload.note && <span style={{ fontSize: 'small' }}> ({userPayload.note})</span>}
|
||||||
{/* TODO narovnat styly pomocí class */}
|
|
||||||
{login === auth.login && canChangeChoice && locationKey === LunchChoice.OBJEDNAVAM && <span title='Označit/odznačit se jako objednávající'>
|
{login === auth.login && canChangeChoice && locationKey === LunchChoice.OBJEDNAVAM && <span title='Označit/odznačit se jako objednávající'>
|
||||||
<FontAwesomeIcon onClick={() => {
|
<FontAwesomeIcon onClick={() => {
|
||||||
markAsBuyer();
|
markAsBuyer();
|
||||||
}} icon={faBasketShopping} color={isBuyer ? '#dbba00' : 'rgb(0, 89, 255)'} style={{marginLeft: '10px', padding: 0, cursor: 'pointer'}} />
|
}} icon={faBasketShopping} className={isBuyer ? 'buyer-icon' : 'action-icon'} style={{cursor: 'pointer'}} />
|
||||||
</span>}
|
</span>}
|
||||||
{login !== auth.login && locationKey === LunchChoice.OBJEDNAVAM && isBuyer && <span title='Objednávající'>
|
{login !== auth.login && locationKey === LunchChoice.OBJEDNAVAM && isBuyer && <span title='Objednávající'>
|
||||||
<FontAwesomeIcon onClick={() => {
|
<FontAwesomeIcon onClick={() => {
|
||||||
copyNote(userPayload.note!);
|
copyNote(userPayload.note!);
|
||||||
}} icon={faBasketShopping} color='#dbba00' style={{marginLeft: '10px', padding: 0}} />
|
}} icon={faBasketShopping} className='buyer-icon' />
|
||||||
</span>}
|
</span>}
|
||||||
{login !== auth.login && canChangeChoice && userPayload?.note?.length && <span title='Převzít poznámku'>
|
{login !== auth.login && canChangeChoice && userPayload?.note?.length && <span title='Převzít poznámku'>
|
||||||
<FontAwesomeIcon onClick={() => {
|
<FontAwesomeIcon onClick={() => {
|
||||||
@ -686,7 +651,10 @@ function App() {
|
|||||||
{
|
{
|
||||||
data.pizzaDay.state === PizzaDayState.DELIVERED &&
|
data.pizzaDay.state === PizzaDayState.DELIVERED &&
|
||||||
<div>
|
<div>
|
||||||
<p>{`Pizzy byly doručeny.${myOrder?.hasQr ? ` Objednávku můžete uživateli ${data.pizzaDay.creator} uhradit pomocí QR kódu níže.` : ''}`}</p>
|
<p>
|
||||||
|
Pizzy byly doručeny.
|
||||||
|
{myOrder?.hasQr ? ` Objednávku můžete uživateli ${data.pizzaDay.creator} uhradit pomocí QR kódu níže.` : ''}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -26,7 +26,7 @@ export default function Login() {
|
|||||||
}, [auth]);
|
}, [auth]);
|
||||||
|
|
||||||
const doLogin = useCallback(async () => {
|
const doLogin = useCallback(async () => {
|
||||||
const length = loginRef?.current?.value.length && loginRef.current.value.replace(/\s/g, '').length
|
const length = loginRef?.current?.value.length && loginRef.current.value.replaceAll(/\s/g, '').length
|
||||||
if (length) {
|
if (length) {
|
||||||
const response = await login({ body: { login: loginRef.current?.value } });
|
const response = await login({ body: { login: loginRef.current?.value } });
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
|
|||||||
@ -75,14 +75,14 @@ export const getDayOfWeekIndex = (date: Date) => {
|
|||||||
|
|
||||||
/** Vrátí první pracovní den v týdnu předaného data. */
|
/** Vrátí první pracovní den v týdnu předaného data. */
|
||||||
export function getFirstWorkDayOfWeek(date: Date) {
|
export function getFirstWorkDayOfWeek(date: Date) {
|
||||||
const firstDay = new Date(date.getTime());
|
const firstDay = new Date(date);
|
||||||
firstDay.setDate(date.getDate() - getDayOfWeekIndex(date));
|
firstDay.setDate(date.getDate() - getDayOfWeekIndex(date));
|
||||||
return firstDay;
|
return firstDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Vrátí poslední pracovní den v týdnu předaného data. */
|
/** Vrátí poslední pracovní den v týdnu předaného data. */
|
||||||
export function getLastWorkDayOfWeek(date: Date) {
|
export function getLastWorkDayOfWeek(date: Date) {
|
||||||
const lastDay = new Date(date.getTime());
|
const lastDay = new Date(date);
|
||||||
lastDay.setDate(date.getDate() + (4 - getDayOfWeekIndex(date)));
|
lastDay.setDate(date.getDate() + (4 - getDayOfWeekIndex(date)));
|
||||||
return lastDay;
|
return lastDay;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,15 +58,15 @@ export default function Header() {
|
|||||||
if (bankAccountNumber) {
|
if (bankAccountNumber) {
|
||||||
try {
|
try {
|
||||||
// Validace kódu banky
|
// Validace kódu banky
|
||||||
if (bankAccountNumber.indexOf('/') < 0) {
|
if (!bankAccountNumber.includes('/')) {
|
||||||
throw Error("Číslo účtu neobsahuje lomítko/kód banky")
|
throw new Error("Číslo účtu neobsahuje lomítko/kód banky")
|
||||||
}
|
}
|
||||||
const split = bankAccountNumber.split("/");
|
const split = bankAccountNumber.split("/");
|
||||||
if (split[1].length !== 4) {
|
if (split[1].length !== 4) {
|
||||||
throw Error("Kód banky musí být 4 číslice")
|
throw new Error("Kód banky musí být 4 číslice")
|
||||||
}
|
}
|
||||||
if (!isValidInteger(split[1])) {
|
if (!isValidInteger(split[1])) {
|
||||||
throw Error("Kód banky není číslo")
|
throw new Error("Kód banky není číslo")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validace čísla a předčíslí
|
// Validace čísla a předčíslí
|
||||||
@ -76,7 +76,7 @@ export default function Header() {
|
|||||||
cislo = cislo.replace('-', '');
|
cislo = cislo.replace('-', '');
|
||||||
}
|
}
|
||||||
if (!isValidInteger(cislo)) {
|
if (!isValidInteger(cislo)) {
|
||||||
throw Error("Předčíslí nebo číslo účtu neobsahuje pouze číslice")
|
throw new Error("Předčíslí nebo číslo účtu neobsahuje pouze číslice")
|
||||||
}
|
}
|
||||||
if (cislo.length < 16) {
|
if (cislo.length < 16) {
|
||||||
cislo = cislo.padStart(16, '0');
|
cislo = cislo.padStart(16, '0');
|
||||||
@ -89,7 +89,7 @@ export default function Header() {
|
|||||||
sum += Number.parseInt(char) * weight
|
sum += Number.parseInt(char) * weight
|
||||||
}
|
}
|
||||||
if (sum % 11 !== 0) {
|
if (sum % 11 !== 0) {
|
||||||
throw Error("Číslo účtu je neplatné")
|
throw new Error("Číslo účtu je neplatné")
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
alert(e.message)
|
alert(e.message)
|
||||||
|
|||||||
@ -15,12 +15,12 @@ export default function PizzaAdditionalFeeModal({ customerName, isOpen, onClose,
|
|||||||
const priceRef = useRef<HTMLInputElement>(null);
|
const priceRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const doSubmit = () => {
|
const doSubmit = () => {
|
||||||
onSave(customerName, textRef.current?.value, parseInt(priceRef.current?.value ?? "0"));
|
onSave(customerName, textRef.current?.value, Number.parseInt(priceRef.current?.value ?? "0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
onSave(customerName, textRef.current?.value, parseInt(priceRef.current?.value ?? "0"));
|
onSave(customerName, textRef.current?.value, Number.parseInt(priceRef.current?.value ?? "0"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,13 +36,13 @@ export default function PizzaCalculatorModal({ isOpen, onClose }: Readonly<Props
|
|||||||
|
|
||||||
// 1. pizza
|
// 1. pizza
|
||||||
if (diameter1Ref.current?.value) {
|
if (diameter1Ref.current?.value) {
|
||||||
const diameter1 = parseInt(diameter1Ref.current?.value);
|
const diameter1 = Number.parseInt(diameter1Ref.current?.value);
|
||||||
r.pizza1 ??= {};
|
r.pizza1 ??= {};
|
||||||
if (diameter1 && diameter1 > 0) {
|
if (diameter1 && diameter1 > 0) {
|
||||||
r.pizza1.diameter = diameter1;
|
r.pizza1.diameter = diameter1;
|
||||||
r.pizza1.area = Math.PI * Math.pow(diameter1 / 2, 2);
|
r.pizza1.area = Math.PI * Math.pow(diameter1 / 2, 2);
|
||||||
if (price1Ref.current?.value) {
|
if (price1Ref.current?.value) {
|
||||||
const price1 = parseInt(price1Ref.current?.value);
|
const price1 = Number.parseInt(price1Ref.current?.value);
|
||||||
if (price1) {
|
if (price1) {
|
||||||
r.pizza1.pricePerM = price1 / r.pizza1.area;
|
r.pizza1.pricePerM = price1 / r.pizza1.area;
|
||||||
} else {
|
} else {
|
||||||
@ -56,13 +56,13 @@ export default function PizzaCalculatorModal({ isOpen, onClose }: Readonly<Props
|
|||||||
|
|
||||||
// 2. pizza
|
// 2. pizza
|
||||||
if (diameter2Ref.current?.value) {
|
if (diameter2Ref.current?.value) {
|
||||||
const diameter2 = parseInt(diameter2Ref.current?.value);
|
const diameter2 = Number.parseInt(diameter2Ref.current?.value);
|
||||||
r.pizza2 ??= {};
|
r.pizza2 ??= {};
|
||||||
if (diameter2 && diameter2 > 0) {
|
if (diameter2 && diameter2 > 0) {
|
||||||
r.pizza2.diameter = diameter2;
|
r.pizza2.diameter = diameter2;
|
||||||
r.pizza2.area = Math.PI * Math.pow(diameter2 / 2, 2);
|
r.pizza2.area = Math.PI * Math.pow(diameter2 / 2, 2);
|
||||||
if (price2Ref.current?.value) {
|
if (price2Ref.current?.value) {
|
||||||
const price2 = parseInt(price2Ref.current?.value);
|
const price2 = Number.parseInt(price2Ref.current?.value);
|
||||||
if (price2) {
|
if (price2) {
|
||||||
r.pizza2.pricePerM = price2 / r.pizza2.area;
|
r.pizza2.pricePerM = price2 / r.pizza2.area;
|
||||||
} else {
|
} else {
|
||||||
@ -77,8 +77,8 @@ export default function PizzaCalculatorModal({ isOpen, onClose }: Readonly<Props
|
|||||||
// Srovnání
|
// Srovnání
|
||||||
if (r.pizza1?.pricePerM && r.pizza2?.pricePerM && r.pizza1.diameter && r.pizza2.diameter) {
|
if (r.pizza1?.pricePerM && r.pizza2?.pricePerM && r.pizza1.diameter && r.pizza2.diameter) {
|
||||||
r.choice = r.pizza1.pricePerM < r.pizza2.pricePerM ? 1 : 2;
|
r.choice = r.pizza1.pricePerM < r.pizza2.pricePerM ? 1 : 2;
|
||||||
const bigger = r.pizza1.pricePerM > r.pizza2.pricePerM ? r.pizza1.pricePerM : r.pizza2.pricePerM;
|
const bigger = Math.max(r.pizza1.pricePerM, r.pizza2.pricePerM);
|
||||||
const smaller = r.pizza1.pricePerM < r.pizza2.pricePerM ? r.pizza1.pricePerM : r.pizza2.pricePerM;
|
const smaller = Math.min(r.pizza1.pricePerM, r.pizza2.pricePerM);
|
||||||
r.ratio = (bigger / smaller) - 1;
|
r.ratio = (bigger / smaller) - 1;
|
||||||
r.diameterDiff = Math.abs(r.pizza1.diameter - r.pizza2.diameter);
|
r.diameterDiff = Math.abs(r.pizza1.diameter - r.pizza2.diameter);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -55,7 +55,7 @@ function useProvideAuth(): AuthContextProps {
|
|||||||
setLoginName(undefined);
|
setLoginName(undefined);
|
||||||
setTrusted(undefined);
|
setTrusted(undefined);
|
||||||
if (trusted && logoutUrl?.length) {
|
if (trusted && logoutUrl?.length) {
|
||||||
window.location.replace(logoutUrl);
|
globalThis.location.replace(logoutUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,8 @@ if (process.env.NODE_ENV === 'development') {
|
|||||||
socketUrl = `http://localhost:3001`;
|
socketUrl = `http://localhost:3001`;
|
||||||
socketPath = undefined;
|
socketPath = undefined;
|
||||||
} else {
|
} else {
|
||||||
socketUrl = `${window.location.host}`;
|
socketUrl = `${globalThis.location.host}`;
|
||||||
socketPath = `${window.location.pathname}socket.io`;
|
socketPath = `${globalThis.location.pathname}socket.io`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const socket = socketio.connect(socketUrl, { path: socketPath, transports: ["websocket"] });
|
export const socket = socketio.connect(socketUrl, { path: socketPath, transports: ["websocket"] });
|
||||||
|
|||||||
@ -17,7 +17,7 @@ client.setConfig({
|
|||||||
// Interceptor na vyhození toasteru při chybě
|
// Interceptor na vyhození toasteru při chybě
|
||||||
client.interceptors.response.use(async response => {
|
client.interceptors.response.use(async response => {
|
||||||
// TODO opravit - login je zatím výjimka, voláme ho "naprázdno" abychom zjistili, zda nás nepřihlásily trusted headers
|
// TODO opravit - login je zatím výjimka, voláme ho "naprázdno" abychom zjistili, zda nás nepřihlásily trusted headers
|
||||||
if (!response.ok && response.url.indexOf("/login") == -1) {
|
if (!response.ok && !response.url.includes("/login")) {
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
toast.error(json.error, { theme: "colored" });
|
toast.error(json.error, { theme: "colored" });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,16 +17,15 @@ const CHART_HEIGHT = 700;
|
|||||||
const STROKE_WIDTH = 2.5;
|
const STROKE_WIDTH = 2.5;
|
||||||
|
|
||||||
const COLORS = [
|
const COLORS = [
|
||||||
// Komentáře jsou kvůli vizualizaci barev ve VS Code
|
'#ff1493',
|
||||||
'#ff1493', // #ff1493
|
'#1e90ff',
|
||||||
'#1e90ff', // #1e90ff
|
'#c5a700',
|
||||||
'#c5a700', // #c5a700
|
'#006400',
|
||||||
'#006400', // #006400
|
'#b300ff',
|
||||||
'#b300ff', // #b300ff
|
'#ff4500',
|
||||||
'#ff4500', // #ff4500
|
'#bc8f8f',
|
||||||
'#bc8f8f', // #bc8f8f
|
'#00ff00',
|
||||||
'#00ff00', // #00ff00
|
'#7c7c7c',
|
||||||
'#7c7c7c', // #7c7c7c
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function StatsPage() {
|
export default function StatsPage() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user