From 08dfbe40abb261b5bd88222cee2b3c35b1a62934 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Thu, 20 Mar 2025 01:16:43 +0000 Subject: [PATCH] form element and styling --- src/Components/Profile/ProfileForm.tsx | 2 + .../Subcomponents/CrowdfundingForm.tsx | 38 +++++++++++++++++++ .../Subcomponents/CrowdfundingView.tsx | 32 +++++++++++----- src/Components/Profile/Templates/FlexForm.tsx | 2 + src/Components/Profile/itemFunctions.ts | 1 + src/types/FormState.d.ts | 1 + src/types/Item.d.ts | 1 + 7 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 src/Components/Profile/Subcomponents/CrowdfundingForm.tsx diff --git a/src/Components/Profile/ProfileForm.tsx b/src/Components/Profile/ProfileForm.tsx index 6f84f689..87252764 100644 --- a/src/Components/Profile/ProfileForm.tsx +++ b/src/Components/Profile/ProfileForm.tsx @@ -45,6 +45,7 @@ export function ProfileForm() { relations: [] as Item[], start: '', end: '', + openCollectiveSlug: '', }) const [updatePermission, setUpdatePermission] = useState(false) @@ -137,6 +138,7 @@ export function ProfileForm() { relations, start: item.start ?? '', end: item.end ?? '', + openCollectiveSlug: item.openCollectiveSlug ?? '', }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [item, tags, items]) diff --git a/src/Components/Profile/Subcomponents/CrowdfundingForm.tsx b/src/Components/Profile/Subcomponents/CrowdfundingForm.tsx new file mode 100644 index 00000000..8ae40a15 --- /dev/null +++ b/src/Components/Profile/Subcomponents/CrowdfundingForm.tsx @@ -0,0 +1,38 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ +import { TextInput } from '#components/Input' + +import type { FormState } from '#types/FormState' + +export const CrowdfundingForm = ({ + state, + setState, +}: { + state: FormState + setState: React.Dispatch> +}) => { + return ( +
+
+ + + setState((prevState) => ({ + ...prevState, + openCollectiveSlug: v, + })) + } + /> +
+
+ ) +} diff --git a/src/Components/Profile/Subcomponents/CrowdfundingView.tsx b/src/Components/Profile/Subcomponents/CrowdfundingView.tsx index 62990b1f..4924ca46 100644 --- a/src/Components/Profile/Subcomponents/CrowdfundingView.tsx +++ b/src/Components/Profile/Subcomponents/CrowdfundingView.tsx @@ -1,5 +1,6 @@ import axios from 'axios' import { useState, useEffect } from 'react' +import { NavLink } from 'react-router-dom' import type { Item } from '#types/Item' @@ -78,7 +79,7 @@ const formatCurrency = (valueInCents: number, currency: string) => { export const CrowdfundingView = ({ item }: { item: Item }) => { // Hier wird slug aus dem Item extrahiert. - const slug = item.slug + const slug = item.openCollectiveSlug const [data, setData] = useState(null) const [loading, setLoading] = useState(true) @@ -139,25 +140,38 @@ export const CrowdfundingView = ({ item }: { item: Item }) => { return (
-
-
-
+
+
+
Current Balance
-
{formatCurrency(currentBalance, currency)}
+
+ {formatCurrency(currentBalance, currency)} +
-
+
Received
-
+
{formatCurrency(stats.totalAmountReceived.valueInCents, currency)}
-
+
Spent
-
+
{formatCurrency(stats.totalAmountReceived.valueInCents - currentBalance, currency)}
+
+
+ + + +
+ Support {item.name} on Open Collective +
+
) diff --git a/src/Components/Profile/Templates/FlexForm.tsx b/src/Components/Profile/Templates/FlexForm.tsx index 5e8d4408..5c5a8928 100644 --- a/src/Components/Profile/Templates/FlexForm.tsx +++ b/src/Components/Profile/Templates/FlexForm.tsx @@ -2,6 +2,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { ContactInfoForm } from '#components/Profile/Subcomponents/ContactInfoForm' +import { CrowdfundingForm } from '#components/Profile/Subcomponents/CrowdfundingForm' import { GroupSubheaderForm } from '#components/Profile/Subcomponents/GroupSubheaderForm' import { ProfileStartEndForm } from '#components/Profile/Subcomponents/ProfileStartEndForm' import { ProfileTextForm } from '#components/Profile/Subcomponents/ProfileTextForm' @@ -14,6 +15,7 @@ const componentMap = { texts: ProfileTextForm, contactInfos: ContactInfoForm, startEnd: ProfileStartEndForm, + crowdfundings: CrowdfundingForm, // weitere Komponenten hier } diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index 7c7443d0..ddf6ca32 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -196,6 +196,7 @@ export const onUpdateItem = async ( ...(state.image.length > 10 && { image: state.image }), ...(state.offers.length > 0 && { offers: offerUpdates }), ...(state.needs.length > 0 && { needs: needsUpdates }), + ...(state.openCollectiveSlug && { openCollectiveSlug: state.openCollectiveSlug }), } const offersState: any[] = [] diff --git a/src/types/FormState.d.ts b/src/types/FormState.d.ts index a7e7f1ee..a0ea8830 100644 --- a/src/types/FormState.d.ts +++ b/src/types/FormState.d.ts @@ -19,4 +19,5 @@ export interface FormState { relations: Item[] start: string end: string + openCollectiveSlug: string } diff --git a/src/types/Item.d.ts b/src/types/Item.d.ts index 1dd7bde4..84dab001 100644 --- a/src/types/Item.d.ts +++ b/src/types/Item.d.ts @@ -50,6 +50,7 @@ export interface Item { telephone?: string next_appointment?: string gallery?: GalleryItem[] + openCollectiveSlug?: string // { // coordinates: [number, number]