From 42782a8db1ed41e40cf13100076aa8573b05f007 Mon Sep 17 00:00:00 2001 From: StefanWout Date: Fri, 18 Oct 2024 14:56:42 +0100 Subject: [PATCH] added state for modal and modal input, added modal html and tested functionality, just need to add api calls to functions and the page should be functional and ready for a design update --- .../settings/PortfolioSettings.tsx | 93 ++++++++++++++++--- 1 file changed, 81 insertions(+), 12 deletions(-) diff --git a/src/app/portfolio/[slug]/(portfolio)/settings/PortfolioSettings.tsx b/src/app/portfolio/[slug]/(portfolio)/settings/PortfolioSettings.tsx index d351544..1c7f888 100644 --- a/src/app/portfolio/[slug]/(portfolio)/settings/PortfolioSettings.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/settings/PortfolioSettings.tsx @@ -15,9 +15,17 @@ import { SelectTrigger, SelectValue, } from "@/app/shadcn_components/ui/select"; +import { + Dialog, + DialogContent, + DialogTitle, + DialogFooter, +} from "@/app/shadcn_components/ui/dialog"; import { PortfolioStatus as PortfolioStatusOptions } from "@/app/db/schema/portfolio"; import { PortfolioGoal as PortfolioGoalOptions } from "@/app/db/schema/portfolio"; +// dropdown selection component for both goal and status + export function SettingsDropdown({ startingValue, options, @@ -59,7 +67,8 @@ export default function PortfolioSettings({ // Running in the client const router = useRouter(); - // Set up state + // Set up state for portfolioName, portfolioBudget, portfolioGoal and portfolioStatus + // Syntax const [variable, function whos only job is to update the value of variable] = useState(initial value) const [portfolioName, setPortfolioName] = useState( portfolioSettingsData.name @@ -77,32 +86,73 @@ export default function PortfolioSettings({ portfolioSettingsData.status ); - // Renaming functionality + // Set up state for deleteModal and deleteConfirmation + + const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false) + + const [deleteConfirmationByName, setDeleteConfirmationByName] = useState("") + + function handleDeleteConfirmation() { + // if (deleteConfirmationByName === portfolioName) + console.log("we be deletin stuff") + } + + // RENAMING FUNCTIONS + + // Change NAME functionality - changing state function handlePortfolioNameChange(e: React.ChangeEvent) { setPortfolioName(e.target.value); } - function handleRename() { + // The onClick function called to update the NAME in the DB + + function handleRenameDb() { // API call to rename the portfolio - // apiFunction(portfolioName) + // apiFunction(portfolioSettingsData.name) // Update portfolioName router.refresh(); } - //Change budget functionality + // BUDGET CHANGING FUNCTIONS + + // Change BUDGET functionality - changing state function handlePortfolioBudgetUpdate(e: React.ChangeEvent) { setPortfolioBudget(Number(e.target.value)); } - function handleBudgetUpdate() { + // The onClick function called to update the BUDGET in the DB + + function handleBudgetUpdateDb() { // API call to change the budget - // apiFunction(portfolioBudget) + // apiFunction(portfolioSettingsData.budget) // Update portfolioBudget router.refresh(); } + // CHANGING GOAL AND STATUS FUNCTIONALITY + + // The onClick function called to update the GOAL in the DB + + function handleGoalUpdateDb() { + // API call to change the goal + // apiFunction(portfolioSettingsData.goal) + // Update portfolioGoal + router.refresh(); + } + + // The onClick function called to update the BUDGET in the DB + + function handleStatusUpdateDb() { + // API call to change the status + // apiFunction(portfolioSettingsData.status) + // Update portfolioStatus + router.refresh(); + } + + // HTML to render the page + return ( <>
@@ -115,7 +165,7 @@ export default function PortfolioSettings({
-
@@ -133,7 +183,7 @@ export default function PortfolioSettings({ />
-
@@ -150,7 +200,7 @@ export default function PortfolioSettings({ setOption={setPortfolioGoal} /> - + {/* Row 4: Status */}
@@ -163,7 +213,7 @@ export default function PortfolioSettings({ setOption={setPortfolioStatus} />
- +
Portfolio Name: {portfolioName}
Portfolio Budget: {portfolioBudget}
@@ -173,10 +223,29 @@ export default function PortfolioSettings({ {/* Row 5: Delete */}
- {/* */} +
+ {/* Delete portfolio modal */} + + + Are you sure? +

+ To confirm, please type the name of the portfolio ({portfolioName}) +

+ setDeleteConfirmationByName(e.target.value)} + placeholder="Type portfolio name" /> + + + + +
+
); } +