Možnost označení objednávajícího
This commit is contained in:
parent
20f4ee0427
commit
e03ba45415
@ -13,12 +13,12 @@ import './App.scss';
|
|||||||
import { faCircleCheck, faNoteSticky, faTrashCan, faComment } from '@fortawesome/free-regular-svg-icons';
|
import { faCircleCheck, faNoteSticky, faTrashCan, faComment } from '@fortawesome/free-regular-svg-icons';
|
||||||
import { useSettings } from './context/settings';
|
import { useSettings } from './context/settings';
|
||||||
import Footer from './components/Footer';
|
import Footer from './components/Footer';
|
||||||
import { faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish, faSearch } from '@fortawesome/free-solid-svg-icons';
|
import { faBasketShopping, faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish, faSearch } from '@fortawesome/free-solid-svg-icons';
|
||||||
import Loader from './components/Loader';
|
import Loader from './components/Loader';
|
||||||
import { getHumanDateTime, isInTheFuture } from './Utils';
|
import { getHumanDateTime, isInTheFuture } from './Utils';
|
||||||
import NoteModal from './components/modals/NoteModal';
|
import NoteModal from './components/modals/NoteModal';
|
||||||
import { useEasterEgg } from './context/eggs';
|
import { useEasterEgg } from './context/eggs';
|
||||||
import { ClientData, Food, PizzaOrder, DepartureTime, PizzaDayState, Restaurant, RestaurantDayMenu, RestaurantDayMenuMap, LunchChoice, UserLunchChoice, PizzaVariant, getData, getEasterEggImage, addPizza, removePizza, updatePizzaDayNote, createPizzaDay, deletePizzaDay, lockPizzaDay, unlockPizzaDay, finishOrder, finishDelivery, addChoice, jdemeObed, removeChoices, removeChoice, updateNote, changeDepartureTime } from '../../types';
|
import { ClientData, Food, PizzaOrder, DepartureTime, PizzaDayState, Restaurant, RestaurantDayMenu, RestaurantDayMenuMap, LunchChoice, UserLunchChoice, PizzaVariant, getData, getEasterEggImage, addPizza, removePizza, updatePizzaDayNote, createPizzaDay, deletePizzaDay, lockPizzaDay, unlockPizzaDay, finishOrder, finishDelivery, addChoice, jdemeObed, removeChoices, removeChoice, updateNote, changeDepartureTime, setBuyer } from '../../types';
|
||||||
import { getLunchChoiceName } from './enums';
|
import { getLunchChoiceName } from './enums';
|
||||||
// import FallingLeaves, { LEAF_PRESETS, LEAF_COLOR_THEMES } from './FallingLeaves';
|
// import FallingLeaves, { LEAF_PRESETS, LEAF_COLOR_THEMES } from './FallingLeaves';
|
||||||
// import './FallingLeaves.scss';
|
// import './FallingLeaves.scss';
|
||||||
@ -284,6 +284,12 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const markAsBuyer = async () => {
|
||||||
|
if (auth?.login) {
|
||||||
|
await setBuyer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const pizzaSuggestions = useMemo(() => {
|
const pizzaSuggestions = useMemo(() => {
|
||||||
if (!data?.pizzaList) {
|
if (!data?.pizzaList) {
|
||||||
return [];
|
return [];
|
||||||
@ -454,9 +460,9 @@ function App() {
|
|||||||
<img alt="" src='snowman.png' style={{ position: "absolute", height: "110px", right: 10, top: 5 }} />
|
<img alt="" src='snowman.png' style={{ position: "absolute", height: "110px", right: 10, top: 5 }} />
|
||||||
Poslední změny:
|
Poslední změny:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Oprava parsování Sladovnické</li>
|
<li>Oprava parsování Sladovnické a TechTower</li>
|
||||||
<li>Oprava parsování cen TechTower</li>
|
|
||||||
<li>Zimní atmosféra</li>
|
<li>Zimní atmosféra</li>
|
||||||
|
<li>Možnost označit se jako objednávající u volby "budu objednávat"</li>
|
||||||
</ul>
|
</ul>
|
||||||
</Alert>
|
</Alert>
|
||||||
{dayIndex != null &&
|
{dayIndex != null &&
|
||||||
@ -534,6 +540,7 @@ function App() {
|
|||||||
const userPayload = entry[1];
|
const userPayload = entry[1];
|
||||||
const userChoices = userPayload?.selectedFoods;
|
const userChoices = userPayload?.selectedFoods;
|
||||||
const trusted = userPayload?.trusted || false;
|
const trusted = userPayload?.trusted || false;
|
||||||
|
const isBuyer = userPayload?.isBuyer || false;
|
||||||
return <tr key={entry[0]}>
|
return <tr key={entry[0]}>
|
||||||
<td>
|
<td>
|
||||||
{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'>
|
||||||
@ -542,6 +549,17 @@ function App() {
|
|||||||
{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í'>
|
||||||
|
<FontAwesomeIcon onClick={() => {
|
||||||
|
markAsBuyer();
|
||||||
|
}} icon={faBasketShopping} color={isBuyer ? '#dbba00' : 'rgb(0, 89, 255)'} style={{marginLeft: '10px', padding: 0, cursor: 'pointer'}} />
|
||||||
|
</span>}
|
||||||
|
{login !== auth.login && locationKey === LunchChoice.OBJEDNAVAM && isBuyer && <span title='Objednávající'>
|
||||||
|
<FontAwesomeIcon onClick={() => {
|
||||||
|
copyNote(userPayload.note!);
|
||||||
|
}} icon={faBasketShopping} color='#dbba00' style={{marginLeft: '10px', padding: 0}} />
|
||||||
|
</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={() => {
|
||||||
copyNote(userPayload.note!);
|
copyNote(userPayload.note!);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
import { getLogin, getTrusted } from "../auth";
|
import { getLogin, getTrusted } from "../auth";
|
||||||
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote, fetchRestaurantWeekMenuData, saveRestaurantWeekMenu } from "../service";
|
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote, fetchRestaurantWeekMenuData, saveRestaurantWeekMenu, updateBuyer } from "../service";
|
||||||
import { getDayOfWeekIndex, parseToken, getFirstWorkDayOfWeek } from "../utils";
|
import { getDayOfWeekIndex, parseToken, getFirstWorkDayOfWeek } from "../utils";
|
||||||
import { getWebsocket } from "../websocket";
|
import { getWebsocket } from "../websocket";
|
||||||
import { callNotifikace } from "../notifikace";
|
import { callNotifikace } from "../notifikace";
|
||||||
@ -182,6 +182,15 @@ router.post("/jdemeObed", async (req, res, next) => {
|
|||||||
} catch (e: any) { next(e) }
|
} catch (e: any) { next(e) }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post("/updateBuyer", async (req, res, next) => {
|
||||||
|
const login = getLogin(parseToken(req));
|
||||||
|
try {
|
||||||
|
const data = await updateBuyer(login);
|
||||||
|
getWebsocket().emit("message", data);
|
||||||
|
res.status(200).json({});
|
||||||
|
} catch (e: any) { next(e) }
|
||||||
|
});
|
||||||
|
|
||||||
// /api/food/refresh?type=week&heslo=docasnyheslo
|
// /api/food/refresh?type=week&heslo=docasnyheslo
|
||||||
export const refreshMetoda = async (req: Request, res: Response) => {
|
export const refreshMetoda = async (req: Request, res: Response) => {
|
||||||
const { type, heslo } = req.query as { type?: string; heslo?: string };
|
const { type, heslo } = req.query as { type?: string; heslo?: string };
|
||||||
|
|||||||
@ -477,6 +477,24 @@ export async function updateDepartureTime(login: string, time?: string, date?: D
|
|||||||
return clientData;
|
return clientData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nastaví/odnastaví uživatele jako objednatele pro dnešní den.
|
||||||
|
* Objednatelů může být více.
|
||||||
|
*
|
||||||
|
* @param login přihlašovací jméno uživatele
|
||||||
|
*/
|
||||||
|
export async function updateBuyer(login: string) {
|
||||||
|
const usedDate = getToday();
|
||||||
|
let clientData = await getClientData(usedDate);
|
||||||
|
const userEntry = clientData.choices?.['OBJEDNAVAM']?.[login];
|
||||||
|
if (!userEntry) {
|
||||||
|
throw new Error("Nelze nastavit objednatele pro uživatele s jinou volbou než \"Budu objednávat\"");
|
||||||
|
}
|
||||||
|
userEntry.isBuyer = !(userEntry.isBuyer || false);
|
||||||
|
await storage.setData(formatDate(usedDate), clientData);
|
||||||
|
return clientData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vrátí data pro klienta pro předaný nebo aktuální den.
|
* Vrátí data pro klienta pro předaný nebo aktuální den.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -26,6 +26,8 @@ paths:
|
|||||||
$ref: "./paths/food/changeDepartureTime.yml"
|
$ref: "./paths/food/changeDepartureTime.yml"
|
||||||
/food/jdemeObed:
|
/food/jdemeObed:
|
||||||
$ref: "./paths/food/jdemeObed.yml"
|
$ref: "./paths/food/jdemeObed.yml"
|
||||||
|
/food/updateBuyer:
|
||||||
|
$ref: "./paths/food/updateBuyer.yml"
|
||||||
|
|
||||||
# Pizza day (/api/pizzaDay)
|
# Pizza day (/api/pizzaDay)
|
||||||
/pizzaDay/create:
|
/pizzaDay/create:
|
||||||
|
|||||||
6
types/paths/food/updateBuyer.yml
Normal file
6
types/paths/food/updateBuyer.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
post:
|
||||||
|
operationId: setBuyer
|
||||||
|
summary: Nastavení/odnastavení aktuálně přihlášeného uživatele jako objednatele pro stav "Budu objednávat" pro aktuální den.
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Stav byl úspěšně změněn.
|
||||||
@ -74,6 +74,9 @@ UserLunchChoice:
|
|||||||
note:
|
note:
|
||||||
description: Volitelná, veřejně viditelná uživatelská poznámka k vybrané volbě
|
description: Volitelná, veřejně viditelná uživatelská poznámka k vybrané volbě
|
||||||
type: string
|
type: string
|
||||||
|
isBuyer:
|
||||||
|
description: Příznak, zda je tento uživatel objednatelem pro stav "Budu objednávat"
|
||||||
|
type: boolean
|
||||||
LocationLunchChoicesMap:
|
LocationLunchChoicesMap:
|
||||||
description: Objekt, kde klíčem je možnost stravování ((#LunchChoice)) a hodnotou množina uživatelů s touto volbou ((#LunchChoices)).
|
description: Objekt, kde klíčem je možnost stravování ((#LunchChoice)) a hodnotou množina uživatelů s touto volbou ((#LunchChoices)).
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user