diff --git a/desktop-app/renderer/api/exchangeAccounts/exchangeAccount.ts b/desktop-app/renderer/api/exchangeAccounts/exchangeAccount.ts index 057f5c46..f9b550b6 100644 --- a/desktop-app/renderer/api/exchangeAccounts/exchangeAccount.ts +++ b/desktop-app/renderer/api/exchangeAccounts/exchangeAccount.ts @@ -3,27 +3,54 @@ import { AxiosResponse } from 'axios' import { useSearchParams } from 'next/navigation' export interface ExchangeAccount { - uuid: string name: string - exchange_name: string + description: string + exchange: string testing: boolean } +export interface RetreivedExchangeAccount extends ExchangeAccount { + uuid: string +} export async function listExchangeAccount( searchParams: ReturnType -): Promise> { +): Promise> { const response = await request(searchParams, 'GET', '/api/exchange_account/') - return response as AxiosResponse + return response as AxiosResponse } export async function getExchangeAccount( searchParams: ReturnType, id: string -): Promise> { +): Promise> { const response = await request( searchParams, 'GET', `/api/exchange_account/${id}/` ) - return response as AxiosResponse + return response as AxiosResponse +} + +export async function createExchangeAccount( + searchParams: ReturnType, + data: ExchangeAccount +): Promise> { + const response = await request( + searchParams, + 'POST', + '/api/exchange_account/', + data + ) + return response as AxiosResponse +} + +export async function getPossibleExchanges( + searchParams: ReturnType +): Promise> { + const response = await request( + searchParams, + 'GET', + '/api/exchange_account/possible_exchanges/' + ) + return response as AxiosResponse } diff --git a/desktop-app/renderer/components/custom/headerPopover.tsx b/desktop-app/renderer/components/custom/headerPopover.tsx index ff72d1e9..c962cee2 100644 --- a/desktop-app/renderer/components/custom/headerPopover.tsx +++ b/desktop-app/renderer/components/custom/headerPopover.tsx @@ -136,10 +136,11 @@ export default function ServerPopover(): JSX.Element { - Add New Server + Add a new Server - Add a new server will allow you to connect to it. You just - have to provide the server name and the server URL. + Adding a new server will allow you to connect to it. You just + have to provide the server name, the server URL and a valid + API key.
diff --git a/desktop-app/renderer/components/custom/panel/infoPanelCard.tsx b/desktop-app/renderer/components/custom/panel/infoPanelCard.tsx index 262347ce..b4866f39 100644 --- a/desktop-app/renderer/components/custom/panel/infoPanelCard.tsx +++ b/desktop-app/renderer/components/custom/panel/infoPanelCard.tsx @@ -4,24 +4,28 @@ import { ReactNode } from 'react' function InfoPanelCard({ title = '', badge = '', - category = '', + textContent = '', + description = '', tooltip = '', onClick = () => {} }: { - title: ReactNode + title?: ReactNode badge?: ReactNode - category?: ReactNode + textContent: ReactNode + description?: ReactNode tooltip?: ReactNode onClick?: () => void }): JSX.Element { return ( -
{title}
+
{textContent}
) } diff --git a/desktop-app/renderer/components/custom/panel/minimalistPanelCard.tsx b/desktop-app/renderer/components/custom/panel/minimalistPanelCard.tsx index 32bfdf18..8be9d008 100644 --- a/desktop-app/renderer/components/custom/panel/minimalistPanelCard.tsx +++ b/desktop-app/renderer/components/custom/panel/minimalistPanelCard.tsx @@ -1,6 +1,6 @@ import PanelCard from '@/components/custom/panel/panelCard' -function MinimalistPanelCard({ +export default function MinimalistPanelCard({ title, tooltip, onClick = () => {} @@ -15,5 +15,3 @@ function MinimalistPanelCard({ ) } - -export default MinimalistPanelCard diff --git a/desktop-app/renderer/components/custom/panel/panelCard.tsx b/desktop-app/renderer/components/custom/panel/panelCard.tsx index 36ebc659..7178faf0 100644 --- a/desktop-app/renderer/components/custom/panel/panelCard.tsx +++ b/desktop-app/renderer/components/custom/panel/panelCard.tsx @@ -7,15 +7,18 @@ import { } from '@/components/ui/card' import React, { ReactNode } from 'react' +import { Badge } from '@/components/ui/badge' import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip' +import { cn } from '@/lib/utils' interface CardComponentProps { children: React.ReactNode + className?: string title?: string | React.ReactNode badge?: string | React.ReactNode description?: string | React.ReactNode @@ -24,28 +27,33 @@ interface CardComponentProps { } const CardComponent = React.forwardRef( - ({ children, title, badge, description, onClick }, ref) => { + ({ children, className, title, badge, description, onClick }, ref) => { return ( - - - {typeof title === 'string' ? ( + + {(title || badge) && ( + {title} - ) : ( - title - )} - {typeof badge === 'string' ? ( -
{badge}
- ) : ( - badge - )} -
- + {badge && ( + + {badge} + + )} +
+ )} + {children} - {typeof description === 'string' ? ( - {description} - ) : ( - description - )} + {description && {description}}
) @@ -54,6 +62,7 @@ const CardComponent = React.forwardRef( export default function PanelCard({ children, + className = '', title = '', badge = '', description = '', @@ -61,6 +70,7 @@ export default function PanelCard({ onClick = () => {} }: { children: ReactNode + className?: string title?: ReactNode badge?: ReactNode description?: ReactNode @@ -70,8 +80,9 @@ export default function PanelCard({ return tooltip ? ( - + ) : ( void -} - function ValuePanelCard({ title = '', badge = '', @@ -40,7 +31,14 @@ function ValuePanelCard({ delta = 0, tooltip = '', onClick = () => {} -}: valuePanelCardProps): JSX.Element { +}: { + title: string | React.ReactNode + badge?: string | React.ReactNode + value: number + delta?: number + tooltip?: string + onClick?: () => void +}): JSX.Element { return ( (defaultExchangeAccount) + + useEffect(() => { + const fetchExchangeAccount = async () => { + try { + const response = await getExchangeAccount( + searchParams, + router.query.slug as string + ) + setExchangeAccount(response.data) + } catch (error) { + console.error(error) + setExchangeAccount(defaultExchangeAccount) + } + } + if (searchParams.get('server')) { + fetchExchangeAccount() + } + }, [searchParams, router.query.slug]) + return ( -

Exchange Account {router.query.slug}

+ +
+
) } diff --git a/desktop-app/renderer/pages/exchangeAccounts/createExchangeAccountDialog.tsx b/desktop-app/renderer/pages/exchangeAccounts/createExchangeAccountDialog.tsx new file mode 100644 index 00000000..77e0cf7e --- /dev/null +++ b/desktop-app/renderer/pages/exchangeAccounts/createExchangeAccountDialog.tsx @@ -0,0 +1,182 @@ +import { Button } from '@/components/ui/button' +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger +} from '@/components/ui/dialog' +import { Input } from '@/components/ui/input' +import { Label } from '@/components/ui/label' +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue +} from '@/components/ui/select' +import { Switch } from '@/components/ui/switch' +import { DialogClose } from '@radix-ui/react-dialog' +import { PlusIcon } from '@radix-ui/react-icons' +import { + RetreivedExchangeAccount, + createExchangeAccount, + getPossibleExchanges +} from 'api/exchangeAccounts/exchangeAccount' +import { useSearchParams } from 'next/navigation' +import { useEffect, useState } from 'react' + +export default function CreateExchangeAccountDialog({ + exchangeAccounts, + setExchangeAccounts +}: { + exchangeAccounts: RetreivedExchangeAccount[] + setExchangeAccounts: React.Dispatch< + React.SetStateAction + > +}): JSX.Element { + const searchParams = useSearchParams() + const defaultExchangeAccountName = 'My Exchange Account' + const defaultExchangeAccountDescription = 'My Exchange Account Description' + const [newExchangeAccountName, setNewExchangeAccountName] = useState( + defaultExchangeAccountName + ) + const [newExchangeAccountDescription, setNewExchangeAccountDescription] = + useState(defaultExchangeAccountDescription) + + const [newExchangeAccountTesting, setNewExchangeAccountTesting] = + useState(true) + + const [possibleExchanges, setPossibleExchanges] = useState([]) + const [selectedExchange, setSelectedExchange] = useState('') + + useEffect(() => { + const fetchPossibleExchanges = async () => { + try { + const response = await getPossibleExchanges(searchParams) + setPossibleExchanges(response.data) + setSelectedExchange(response.data[0]) + } catch (error) { + console.error(error) + setPossibleExchanges([]) + } + } + + if (searchParams.get('server')) { + fetchPossibleExchanges() + } + }, [searchParams]) + return ( + + + + + + + Add a new Exchange Account + + Add a new server will allow you to connect to it. You just have to + provide the server name and the server URL. + + +
+
+
+ + { + setNewExchangeAccountName(e.currentTarget.value) + }} + /> +
+
+ + { + setNewExchangeAccountDescription(e.currentTarget.value) + }} + /> +
+
+ + +
+
+ + { + setNewExchangeAccountTesting(!newExchangeAccountTesting) + }} + /> +
+
+
+
+ +
+
+ +
+ ) +} diff --git a/desktop-app/renderer/pages/exchangeAccounts/index.tsx b/desktop-app/renderer/pages/exchangeAccounts/index.tsx index 639f4e7d..369f366e 100644 --- a/desktop-app/renderer/pages/exchangeAccounts/index.tsx +++ b/desktop-app/renderer/pages/exchangeAccounts/index.tsx @@ -3,21 +3,23 @@ import ContextHeader from '@/components/layout/contextHeader' import DefaultPageLayout from '@/components/layout/defaultPageLayout' import { standardUrlPartial } from '@/lib/queryParams' import { - ExchangeAccount, + RetreivedExchangeAccount, listExchangeAccount } from 'api/exchangeAccounts/exchangeAccount' import { useSearchParams } from 'next/navigation' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' +import CreateExchangeAccountDialog from './createExchangeAccountDialog' export default function ExchangeAccounts(): JSX.Element { - const [exchangeAccounts, setExchangeAccounts] = useState( - [] - ) const searchParams = useSearchParams() const router = useRouter() + const [exchangeAccounts, setExchangeAccounts] = useState< + RetreivedExchangeAccount[] + >([]) + useEffect(() => { - const fetchData = async () => { + const fetchExchangeAccounts = async () => { try { const response = await listExchangeAccount(searchParams) setExchangeAccounts(response.data) @@ -26,22 +28,26 @@ export default function ExchangeAccounts(): JSX.Element { setExchangeAccounts([]) } } - fetchData() - }, [searchParams]) + if (searchParams.get('server')) { + fetchExchangeAccounts() + } + }, [searchParams]) return (
{exchangeAccounts.map((exchangeAccount, index) => ( { router.push( standardUrlPartial( @@ -59,6 +65,15 @@ export default function ExchangeAccounts(): JSX.Element { }} /> ))} + + } + />