From 9e9ed219b16da2d290c5727449e75906f7d54042 Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 22:46:20 -0500 Subject: [PATCH 01/15] fix(many): luuk's feedback --- src/app/(auth)/signin/page.tsx | 16 +--------------- src/app/(auth)/signup/page.tsx | 12 +----------- src/app/api/communities/route.ts | 2 +- .../auth/signup/ChooseCommunity/index.tsx | 3 +-- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/app/(auth)/signin/page.tsx b/src/app/(auth)/signin/page.tsx index d196b87..ad34760 100644 --- a/src/app/(auth)/signin/page.tsx +++ b/src/app/(auth)/signin/page.tsx @@ -36,21 +36,7 @@ export default function Page() { Or - - - + diff --git a/src/app/(auth)/signup/page.tsx b/src/app/(auth)/signup/page.tsx index 05a9138..9363d9a 100644 --- a/src/app/(auth)/signup/page.tsx +++ b/src/app/(auth)/signup/page.tsx @@ -36,17 +36,7 @@ export default function Page() { - - - - - - - + diff --git a/src/app/api/communities/route.ts b/src/app/api/communities/route.ts index 44a2bdd..16acd77 100644 --- a/src/app/api/communities/route.ts +++ b/src/app/api/communities/route.ts @@ -60,7 +60,7 @@ async function updateCommunities() { return console.log("Updating " + community.name) const communityData = await gatherContractInfo(community.contract_address, community.last_block) - const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact', head: true }).eq('community', community.id); + const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact'})//.eq('community', community.id); console.log("Current comunity ", community) community.transfers = communityData.transfers community.members = communityData.members diff --git a/src/components/auth/signup/ChooseCommunity/index.tsx b/src/components/auth/signup/ChooseCommunity/index.tsx index f702bce..d4a1073 100644 --- a/src/components/auth/signup/ChooseCommunity/index.tsx +++ b/src/components/auth/signup/ChooseCommunity/index.tsx @@ -12,7 +12,6 @@ import { useQuery } from '@tanstack/react-query' import communitiesService from '@/features/communities/services/communities.service' const ChooseCommunity = (): ReactElement => { - const { data, isLoading, error, refetch } = useQuery({ queryKey: ['getCommunities'], queryFn: async () => await communitiesService.get(), @@ -22,7 +21,7 @@ const ChooseCommunity = (): ReactElement => { const [step, setStep] = useState(1) const handleChange = (community: Community) => { - setSelectedCommunity(community) + if (community.id == 'Trinidad') setSelectedCommunity(community) } const handleNextStep = () => { From fe88b3ebb93738fb949a7197d71e0c4a272dd16c Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 23:12:07 -0500 Subject: [PATCH 02/15] fix(communities): vendor total count --- src/app/api/communities/route.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/app/api/communities/route.ts b/src/app/api/communities/route.ts index 16acd77..a087352 100644 --- a/src/app/api/communities/route.ts +++ b/src/app/api/communities/route.ts @@ -48,19 +48,27 @@ async function updateCommunities() { const supabaseClient = createAnonymousClient() - const { data, error } = await supabaseClient.from(COMMUNITIES).select('*') - .lte('last_update', new Date(Date.now() - 3600 * 1000).toISOString()); + const { data, error } = await supabaseClient.from(COMMUNITIES).select('*')); if (error) throw new Error(`Error gathering communities: ${error}`) console.log("Communities " + data.length) - data.forEach(async community => { - if (community.id != 'Trinidad') + const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact' }).eq('community', community.id); + let updateResult = await supabaseClient + .from(COMMUNITIES) + .update({ vendors: vendorsData.count }) + .eq('id', community.id) + .select() + .single() + + if (community.id != 'Trinidad' || community.last_update >= new Date(Date.now() - 3600 * 1000).toISOString()) return + + console.log("Updating " + community.name) const communityData = await gatherContractInfo(community.contract_address, community.last_block) - const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact'})//.eq('community', community.id); + console.log("Current comunity ", community) community.transfers = communityData.transfers community.members = communityData.members @@ -68,7 +76,7 @@ async function updateCommunities() { community.last_block = communityData.last_block community.vendors = vendorsData.count console.log("Before saving ", community) - let updateResult = await supabaseClient + updateResult = await supabaseClient .from(COMMUNITIES) .update(community) .eq('id', community.id) @@ -83,6 +91,9 @@ async function updateCommunities() { if (updateResult.error != null) throw new Error(`Error updating communities: ${error}`) }); + + + return true; } From f0390160e2168693f22e8556f51a04b27d417c9a Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 23:27:04 -0500 Subject: [PATCH 03/15] feat(communities): vendor total optmization --- src/app/api/communities/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/communities/route.ts b/src/app/api/communities/route.ts index a087352..4eeb87c 100644 --- a/src/app/api/communities/route.ts +++ b/src/app/api/communities/route.ts @@ -48,7 +48,7 @@ async function updateCommunities() { const supabaseClient = createAnonymousClient() - const { data, error } = await supabaseClient.from(COMMUNITIES).select('*')); + const { data, error } = await supabaseClient.from(COMMUNITIES).select('*'); if (error) throw new Error(`Error gathering communities: ${error}`) console.log("Communities " + data.length) From 822330d9df3c1f41881c99d982d17d4eed859881 Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 23:33:03 -0500 Subject: [PATCH 04/15] feat(community): tracing vendors count --- src/app/api/communities/route.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/api/communities/route.ts b/src/app/api/communities/route.ts index 4eeb87c..1991671 100644 --- a/src/app/api/communities/route.ts +++ b/src/app/api/communities/route.ts @@ -55,12 +55,16 @@ async function updateCommunities() { data.forEach(async community => { const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact' }).eq('community', community.id); + console.log("Vendors for " + community.id + ': ' + vendorsData.count) let updateResult = await supabaseClient .from(COMMUNITIES) .update({ vendors: vendorsData.count }) .eq('id', community.id) .select() .single() + if (updateResult.error != null) + throw new Error(`Error updating communities: ${error}`) + if (community.id != 'Trinidad' || community.last_update >= new Date(Date.now() - 3600 * 1000).toISOString()) return From afb17546bb494ac1225daa0e878d12d4b7b117b3 Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 23:44:36 -0500 Subject: [PATCH 05/15] feat(communities): active vendors realtime --- src/app/api/communities/route.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/app/api/communities/route.ts b/src/app/api/communities/route.ts index 1991671..b74b72c 100644 --- a/src/app/api/communities/route.ts +++ b/src/app/api/communities/route.ts @@ -18,11 +18,13 @@ export async function GET() { const { data, error } = await supabaseClient.from(COMMUNITIES).select('*', { head: false }).not('id', 'is', null) if (error) return NextResponse.json(error, { status: 500 }) + + const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact' }).not('id', 'is', null); const response = { tokensInCirculation: formatCurrency(data.reduce((sum, item) => sum + item.tokens, 0) * 0.15, 'Dollard'), tokenTransfers: data.reduce((sum, item) => sum + item.transfers, 0), members: data.reduce((sum, item) => sum + item.members, 0), - activeVendors: data.reduce((sum, item) => sum + item.vendors, 0), + activeVendors: vendorsData.count, communities: data.map(community => ({ id: community.id, name: community.name, @@ -54,18 +56,6 @@ async function updateCommunities() { data.forEach(async community => { - const vendorsData = await supabaseClient.from('vendors').select('*', { count: 'exact' }).eq('community', community.id); - console.log("Vendors for " + community.id + ': ' + vendorsData.count) - let updateResult = await supabaseClient - .from(COMMUNITIES) - .update({ vendors: vendorsData.count }) - .eq('id', community.id) - .select() - .single() - if (updateResult.error != null) - throw new Error(`Error updating communities: ${error}`) - - if (community.id != 'Trinidad' || community.last_update >= new Date(Date.now() - 3600 * 1000).toISOString()) return @@ -78,9 +68,8 @@ async function updateCommunities() { community.members = communityData.members community.tokens = communityData.tokens community.last_block = communityData.last_block - community.vendors = vendorsData.count console.log("Before saving ", community) - updateResult = await supabaseClient + let updateResult = await supabaseClient .from(COMMUNITIES) .update(community) .eq('id', community.id) From 692dda49131d9781480239f541c6ccbef68758cd Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 23:54:55 -0500 Subject: [PATCH 06/15] fix(sing up): google sing up wasnt working --- src/app/(auth)/signup/page.tsx | 11 +++-------- .../auth/signin/ButtonSignInGoogle/index.tsx | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/app/(auth)/signup/page.tsx b/src/app/(auth)/signup/page.tsx index 9363d9a..1824673 100644 --- a/src/app/(auth)/signup/page.tsx +++ b/src/app/(auth)/signup/page.tsx @@ -1,11 +1,8 @@ import HeaderCard from '@/components/common/cards/HeaderCard' import { Card, CardContent, Typography, Stack, Container, TextField, Button, Box } from '@mui/material' import { type Metadata } from 'next' -import Image from 'next/image' -import IconGoogle from '@/public/images/icons/google.svg?url' -import IconFacebook from '@/public/images/icons/facebook.svg?url' -import IconApple from '@/public/images/icons/apple.svg?url' import Link from 'next/link' +import ButtonSignInGoogle from '@/components/auth/signin/ButtonSignInGoogle' export const metadata: Metadata = { title: 'Sign Up', @@ -33,10 +30,8 @@ export default function Page() { - - + + diff --git a/src/components/auth/signin/ButtonSignInGoogle/index.tsx b/src/components/auth/signin/ButtonSignInGoogle/index.tsx index 85f6a61..d7cca72 100644 --- a/src/components/auth/signin/ButtonSignInGoogle/index.tsx +++ b/src/components/auth/signin/ButtonSignInGoogle/index.tsx @@ -7,7 +7,7 @@ import Image from 'next/image' import LoadingButton from '@/components/common/buttons/LoadingButton' import { Stack, Typography } from '@mui/material' -const ButtonSignInGoogle = (): ReactElement => { +const ButtonSignInGoogle = ({ up }: { up: boolean }): ReactElement => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) @@ -35,7 +35,7 @@ const ButtonSignInGoogle = (): ReactElement => { fullWidth disabledMargin > - Continue with Google + {up ? '' : 'Continue with Google'} {error && ( From 4aaf17285a5db942e4cd9442c46e2855b9f5ce20 Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Tue, 10 Dec 2024 23:56:26 -0500 Subject: [PATCH 07/15] feat(sing in): componentization google button --- src/app/(auth)/signin/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/(auth)/signin/page.tsx b/src/app/(auth)/signin/page.tsx index ad34760..dd9aa83 100644 --- a/src/app/(auth)/signin/page.tsx +++ b/src/app/(auth)/signin/page.tsx @@ -36,7 +36,7 @@ export default function Page() { Or - + From 4c52f86b3250e4b966edaf15139c7e9901e5006b Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Wed, 11 Dec 2024 00:04:16 -0500 Subject: [PATCH 08/15] feat(home): fixing home route --- src/components/common/Layout/AppBar/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/common/Layout/AppBar/index.tsx b/src/components/common/Layout/AppBar/index.tsx index 1660335..df27955 100644 --- a/src/components/common/Layout/AppBar/index.tsx +++ b/src/components/common/Layout/AppBar/index.tsx @@ -70,7 +70,7 @@ export default function CustomAppBar({ - + - + /> - - - What are the requirements for the attendee? - - {requirements.split(',').map((requirement, index) => ( - - handleRequirementsChange(event, index)} - value={requirement} - sx={{ width: '100%' }} - slotProps={{ - htmlInput: { ...register('requirements') }, - }} - error={!!errors?.requirements} - > - - Select requirement - - {requirementsOptions.map((requirementOption) => ( - - {requirementOption.label} - - ))} - - {/* {requirements.length > 1 && ( - - )} */} - - ))} - - - - - {/* */} Date: Sat, 14 Dec 2024 04:06:42 -0500 Subject: [PATCH 14/15] feat(activities): unify host Id with user Id --- src/app/api/activities/route.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/api/activities/route.ts b/src/app/api/activities/route.ts index fe0e5d1..59f13ed 100644 --- a/src/app/api/activities/route.ts +++ b/src/app/api/activities/route.ts @@ -1,7 +1,8 @@ import type { NextRequest } from 'next/server' import { NextResponse } from 'next/server' -import { createClient } from '@supabase/supabase-js' +import { createClient } from '@/utils/supabase/server' import { type ActivityType } from '@/types/activities' +import { createAnonymousClient } from '@/utils/supabase/anonymousClient' const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || '' const supabaseBucket = process.env.NEXT_PUBLIC_SUPABASE_BUCKET || '' @@ -12,11 +13,14 @@ const ACTIVITIES = 'activities' const ORGANIZATIONS = 'organizations' export async function GET(req: NextRequest) { - console.log('aca-organ') + const { searchParams } = new URL(req.url) const id = searchParams.get('id') - const hostId = searchParams.get('hostId') - const supabaseClient = createClient(supabaseUrl, supabaseAnonKey) + const supabaseClientAuth = createClient() + const user = await supabaseClientAuth.auth.getUser() + const hostId = user.data.user?.id + + const supabaseClient = createAnonymousClient() if (hostId && id) { const { data, error } = await supabaseClient .from(ACTIVITIES) From 58a6317c671575351255f98fbf11be64768b42fe Mon Sep 17 00:00:00 2001 From: voyager-seb Date: Sat, 14 Dec 2024 04:15:15 -0500 Subject: [PATCH 15/15] feat(activities): choring --- src/app/api/activities/route.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/api/activities/route.ts b/src/app/api/activities/route.ts index 59f13ed..b5ea1de 100644 --- a/src/app/api/activities/route.ts +++ b/src/app/api/activities/route.ts @@ -101,7 +101,7 @@ export async function GET(req: NextRequest) { } export async function POST(req: NextRequest) { - const supabaseClient = createClient(supabaseUrl, supabaseAnonKey) + const supabaseClient = createAnonymousClient() const newActivity = (await req.json()) as ActivityType @@ -154,7 +154,7 @@ export async function PUT(req: NextRequest) { export async function DELETE(req: NextRequest) { const id = await req.json().then((body) => body.id) - const supabaseClient = createClient(supabaseUrl, supabaseAnonKey) + const supabaseClient = createAnonymousClient() const { data, error } = await supabaseClient.from(ACTIVITIES).delete().eq('id', id) if (error) return NextResponse.json(error) return NextResponse.json(data) @@ -163,7 +163,7 @@ export async function DELETE(req: NextRequest) { async function uploadFile(bucketName: string, filePath: string, base64File: string) { console.log('FilePath: ', filePath) const fileBlob = await base64ImageSourceToBlob(base64File) - const supabaseClient = createClient(supabaseUrl, supabaseAnonKey) + const supabaseClient = createAnonymousClient() const { data: dataDelete, error: errorDelete } = await supabaseClient.storage.from(bucketName).remove([filePath]) if (errorDelete) { console.error('Error uploading file:', errorDelete.message) @@ -183,7 +183,7 @@ async function uploadFile(bucketName: string, filePath: string, base64File: stri async function downloadFile(bucketName: string, filePath: string) { if (filePath == '' || !filePath) return '' - const supabaseClient = createClient(supabaseUrl, supabaseAnonKey) + const supabaseClient = createAnonymousClient() const { data, error } = await supabaseClient.storage.from(bucketName).download(filePath) if (error) { @@ -208,7 +208,7 @@ async function base64ImageSourceToBlob(base64imageSource: string): Promise } async function updateActivity(activity: ActivityType) { - const supabaseClient = createClient(supabaseUrl, supabaseAnonKey) + const supabaseClient = createAnonymousClient() const { banner_src: banner_src, ...organizationWithoutLogoSrc } = activity console.log('Removed ', banner_src?.substring(0, 10))