From 22b6298c42d38ce359fcc2bc6a50ffb3aa43f65a Mon Sep 17 00:00:00 2001 From: Romain Lebbadi-Breteau <romain@lebbadi.fr> Date: Sun, 5 Feb 2023 10:18:45 -0500 Subject: [PATCH] Your heart's been aching but you're too shy to say it --- .env | 2 + .../controllers/TransactionComponant.tsx | 105 +++++++++++------- assets/react/controllers/TransactionList.tsx | 2 +- config/services.yaml | 3 + src/Service/CategoryService.php | 8 +- 5 files changed, 77 insertions(+), 43 deletions(-) diff --git a/.env b/.env index 70a631e..c6b213c 100644 --- a/.env +++ b/.env @@ -42,3 +42,5 @@ DATABASE_URL="postgresql://app:!ChangeMe!@database:5432/app?serverVersion=15&cha ###> symfony/mailer ### # MAILER_DSN=null://null ###< symfony/mailer ### + +GOOGLE_MAPS_API_KEY=... \ No newline at end of file diff --git a/assets/react/controllers/TransactionComponant.tsx b/assets/react/controllers/TransactionComponant.tsx index 935945e..b971a8b 100644 --- a/assets/react/controllers/TransactionComponant.tsx +++ b/assets/react/controllers/TransactionComponant.tsx @@ -26,6 +26,49 @@ export default function TransactionComponant(props: { const [isEditing, setIsEditing] = React.useState(props.isEditing); + const categoryMap = [ + { + "value": "auto-detect", + "label": "Détection automatique", + }, + { + "value": "restaurant", + "label": "Restaurant" + }, + { + "value": "bar", + "label": "Bar" + }, + { + "value": "store", + "label": "Magasin" + }, + { + "value": "groceries", + "label": "Épicerie", + }, + { + "value": "sport", + "label": "Sport", + }, + { + "value": "transport", + "label": "Transport" + }, + { + "value": "subscription", + "label": "Abonnement" + }, + { + "value": "education", + "label": "Éducation" + }, + { + "value": "other", + "label": "Autre" + } + ] + React.useEffect(() => { if (version !== props.transaction.version) { setCategory(props.transaction.category); @@ -63,7 +106,6 @@ export default function TransactionComponant(props: { type="text" value={location} onChange={(e) => setLocation(e.target.value)} - placeholder="location" required /> </div> @@ -74,56 +116,39 @@ export default function TransactionComponant(props: { type="text" value={description} onChange={(e) => setDescription(e.target.value)} - placeholder="description" required /> </div> <div style={{ marginBottom: "10px" }}> <strong>Categorie : </strong> - <label htmlFor="category"></label> - <datalist id="category_id"> - <option value="Restaurant">Restaurant</option> - <option value="Bar">Bar</option> - <option value="Store">Store</option> - <option value="Grocerie">Grocerie</option> - <option value="Sport">Sport</option> - <option value="Transport">Transport</option> - <option value="Subscription">Subscription</option> - <option value="Auto-detect">Auto-detect</option> - <option value="Other">Other</option> - </datalist> + <label htmlFor="category" style={{ minWidth: "100px" }}></label> + <select value={category} onChange={e => setCategory(e.target.value)}> + {categoryMap.map((elem) => ( + <option value={elem.value}>{elem.label}</option> + ))} + </select> + </div> + <div style={{ marginBottom: "10px" }}> + <strong>Date : </strong> + <label htmlFor="date" style={{ minWidth: "100px" }}></label> <input - type="select" - list="category_id" - value={category} - onChange={(e) => setCategory(e.target.value)} - placeholder="category" + type="date" + value={date} + onChange={(e) => setDate(e.target.value)} required /> </div> - <div style={{ marginBottom: "10px" }}> + <div> <strong>Montant : </strong> <label htmlFor="amount"></label> <input type="number" value={amount} onChange={(e) => setAmount(Number(e.target.value))} - placeholder="amount" required />{" "} <strong> $</strong> </div> - <div> - <strong>Date : </strong> - <label htmlFor="date"></label> - <input - type="date" - value={date} - onChange={(e) => setDate(e.target.value)} - placeholder="date" - required - /> - </div> <div> <strong>Revenu : </strong>{" "} <input @@ -142,26 +167,26 @@ export default function TransactionComponant(props: { </> ) : ( <> - <div> + <div style={{ marginBottom: "10px" }}> <strong>Lieu : </strong> {location} </div> - <div> + <div style={{ marginBottom: "10px" }}> <strong>Description : </strong> {description} </div> - <div> + <div style={{ marginBottom: "10px" }}> <strong>Categorie : </strong> - {category} + {categoryMap.find(cat => cat.value === category).label} + </div> + <div style={{ marginBottom: "10px" }}> + <strong>Date : </strong> + {date} </div> <div> <strong>Montant : </strong> {amount.toFixed(2)} $ </div> - <div> - <strong>Date : </strong> - {date} - </div> <div> <strong>Revenu : </strong>{" "} <input diff --git a/assets/react/controllers/TransactionList.tsx b/assets/react/controllers/TransactionList.tsx index 10c13e2..98e0be5 100644 --- a/assets/react/controllers/TransactionList.tsx +++ b/assets/react/controllers/TransactionList.tsx @@ -55,7 +55,7 @@ export default function TransactionList() { <h1> Mes transactions <strong onClick={() => { - setTransactions([{ expense: true, category: 'auto-detect', version: 0 }, ...transactions]); + setTransactions([{ expense: true, category: 'auto-detect', version: 0, amount: 0, date: new Date().toISOString().split('T')[0] }, ...transactions]); }} className="icone" id="btn-ajouter" style={{ marginLeft: "20px", paddingRight: "5px" }}> <i className="fa-solid fa-plus" /> Ajouter </strong> </h1> </div> diff --git a/config/services.yaml b/config/services.yaml index 2d6a76f..e7680fb 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -22,3 +22,6 @@ services: # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones + App\Service\CategoryService: + arguments: + $apiKey: '%env(GOOGLE_MAPS_API_KEY)%' \ No newline at end of file diff --git a/src/Service/CategoryService.php b/src/Service/CategoryService.php index 13f700d..f39abbc 100644 --- a/src/Service/CategoryService.php +++ b/src/Service/CategoryService.php @@ -7,6 +7,7 @@ class CategoryService { private string $baseUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"; private $categoriesWhitelist = ["restaurant", "bar", "store"]; private $categoriesMap = [ + "university" => "education", "supermarket" => "groceries", "grocery_or_supermarket" => "groceries", "bicycle_store" => "sport", @@ -14,7 +15,7 @@ class CategoryService { "transit_station" => "transport", "airport" => "transport", "gas_station" => "transport", - "car_dealership" => "transport" + "car_dealership" => "transport", ]; private $wikipediaMap = [ "e-commerce" => "store", @@ -22,8 +23,11 @@ class CategoryService { ]; private $wikipediaWhitelist = ["subscription"]; - public function __construct() { + private string $apiKey; + + public function __construct(string $apiKey) { $this->ch = curl_init(); + $this->apiKey = $apiKey; } public function __destruct() { -- GitLab