From 326a2d3c271587976097e1a33f66fb8046a4338b Mon Sep 17 00:00:00 2001 From: Sidhin S Thomas Date: Wed, 14 Aug 2024 02:20:27 +0530 Subject: [PATCH] Integrate link budget --- ui/components/header.tsx | 20 ++++++- ui/components/link_budget_modal.tsx | 87 +++++++++++++++++++++++++++++ ui/services/share_service.ts | 11 +++- 3 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 ui/components/link_budget_modal.tsx diff --git a/ui/components/header.tsx b/ui/components/header.tsx index b515c3d..1b31ad1 100644 --- a/ui/components/header.tsx +++ b/ui/components/header.tsx @@ -25,6 +25,7 @@ import { connect } from "react-redux"; import { budgetSlice, headerSlice, navigate, store, View } from "../store"; import { GetScreenSize, ScreenSize } from "../utils"; import { ShareBudgetModal } from "./share_budget_modal"; +import { LinkBudgetModal } from "./link_budget_modal"; export interface HeaderBudgetDetails { name: string; @@ -42,6 +43,7 @@ export interface HeaderProps { interface HeaderState { is_budget_selector_visible: boolean; open_share_modal: boolean; + open_link_modal: boolean; } class Header extends React.Component { @@ -73,6 +75,7 @@ class Header extends React.Component { this.state = { is_budget_selector_visible: false, open_share_modal: false, + open_link_modal: false, }; } @@ -96,15 +99,20 @@ class Header extends React.Component { store.dispatch(budgetSlice.actions.updateSelection({ index: null })); store.dispatch(navigate(View.NoBudgetAvailable)); }; + const linkBudget = (e: React.MouseEvent) => { + this.setState({ open_link_modal: true }); + e.preventDefault(); + } const onSelectionChanged = (value: number) => { store.dispatch(budgetSlice.actions.updateSelection({ index: value })); - } + }; const onSettingsClicked = () => { this.setState({ is_budget_selector_visible: false }); store.dispatch(navigate(View.NoBudgetAvailable)); - } + }; return ( + <> + + + + ); +} \ No newline at end of file diff --git a/ui/services/share_service.ts b/ui/services/share_service.ts index 2e257c7..71632c9 100644 --- a/ui/services/share_service.ts +++ b/ui/services/share_service.ts @@ -26,9 +26,18 @@ export interface ShareKeyResponse { export async function GetShareKey(budget_id: string): Promise { if (import.meta.env.VITE_USE_LOCAL_DATA_SERVICE === 'true') { - await new Promise((resolve,_reject) => _reject("Failed")); + await new Promise((resolve,_reject) => setTimeout(resolve, 3000)); return { shareKey: "2U0T0Y05" }; } const response = await fetchData(`/api/Social/share_code/${budget_id}`, {method:"POST"}); return await response.json(); +} + +export async function LinkBudget(share_key: string): Promise { + if (import.meta.env.VITE_USE_LOCAL_DATA_SERVICE === 'true') { + await new Promise((resolve,_reject) => setTimeout(resolve, 3000)); + return; + } + await fetchData(`/api/Social/link/${share_key}`, {method:"POST"}); + return; } \ No newline at end of file