Skip to content

Commit

Permalink
Fix build errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
bLopata committed Oct 25, 2024
1 parent 31b79dd commit a3e7488
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4,017 deletions.
24 changes: 13 additions & 11 deletions www/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FaLightbulb, FaPaperPlane } from 'react-icons/fa';
import Swal from 'sweetalert2';

import { useRef, useEffect, useState, ElementRef } from 'react';
import { redirect } from 'next/navigation';
import { useRouter } from 'next/navigation';
import { usePostHog } from 'posthog-js/react';

import { getSubscription } from '@/utils/supabase/queries';
Expand Down Expand Up @@ -43,6 +43,7 @@ export default function Home() {

const [conversationId, setConversationId] = useState<string>();

const router = useRouter();
const supabase = createClient();
const posthog = usePostHog();
const input = useRef<ElementRef<'textarea'>>(null);
Expand Down Expand Up @@ -75,17 +76,18 @@ export default function Home() {
confirmButtonColor: '#3085d6',
confirmButtonText: 'Sign In',
});
redirect('/auth');
}
setUserId(user.id);
posthog?.identify(userId, { email: user.email });

// Check subscription status
if (process.env.NEXT_PUBLIC_STRIPE_ENABLED === 'false') {
setIsSubscribed(true);
router.push('/auth');
} else {
const sub = await getSubscription(supabase);
setIsSubscribed(!!sub);
setUserId(user.id);
posthog?.identify(userId, { email: user.email });

// Check subscription status
if (process.env.NEXT_PUBLIC_STRIPE_ENABLED === 'false') {
setIsSubscribed(true);
} else {
const sub = await getSubscription(supabase);
setIsSubscribed(!!sub);
}
}
})();
}, [supabase, posthog, userId]);
Expand Down
10 changes: 5 additions & 5 deletions www/app/settings/SettingsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { SupportSettings } from '@/components/settings/SupportSettings';
import { User } from '@supabase/supabase-js';

interface SettingsProps {
user?: User | null;
subscription?: any; // Change this to the correct type when available
products?: any[]; // Change this to the correct type when available
user: User | null;
subscription?: any | null; // Change this to the correct type when available
products?: any[] | null; // Change this to the correct type when available
}

export default function SettingsLayout({
Expand Down Expand Up @@ -57,8 +57,8 @@ export default function SettingsLayout({
{activeTab === 'security' && <SecuritySettings user={user} />}
{activeTab === 'subscription' && (
<SubscriptionSettings
subscription={subscription}
products={products}
subscription={subscription ?? null}
products={products ?? null}
/>
)}
{activeTab === 'integrations' && <IntegrationsSettings />}
Expand Down
9 changes: 5 additions & 4 deletions www/components/settings/AccountSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { SettingsForm } from '@/components/settings/SettingsForm';
import { User } from '@supabase/supabase-js';

interface User {
id: string;
email: string;
interface AccountSettingsProps {
user: User | null;
}

export function AccountSettings({ user }: { user: User }) {
export function AccountSettings({ user }: AccountSettingsProps) {
if (!user) return <div>Please log in to view account settings.</div>;
return (
<div className="space-y-4">
<h2 className="text-3xl font-bold text-primary">Account Settings</h2>
Expand Down
27 changes: 14 additions & 13 deletions www/components/settings/IntegrationsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ const fetcher = async () => {
const supabase = createClient();

// Get the user's identities
const {
data: { identities },
error: identitiesError,
} = await supabase.auth.getUserIdentities();
const { data, error: identitiesError } =
await supabase.auth.getUserIdentities();

if (!data || !data.identities) {
console.error('No identities found');
return { error: 'No identities found' };
}

if (identitiesError) {
console.error('Error fetching user identities:', identitiesError);
return { error: 'Failed to fetch user identities' };
}

const discordIdentity = identities?.find(
const discordIdentity = data.identities.find(
(identity: UserIdentity) => identity.provider === 'discord'
);

Expand All @@ -39,14 +42,12 @@ const fetcher = async () => {

return {
isDiscordConnected: !!discordIdentity,
discordTag: discordIdentity
? discordIdentity.identity_data.global_name ||
discordIdentity.identity_data.name
: null,
discordAvatar: discordIdentity
? discordIdentity.identity_data.avatar_url
: null,
discordEmail: discordIdentity ? discordIdentity.identity_data.email : null,
discordTag:
discordIdentity?.identity_data?.global_name ||
discordIdentity?.identity_data?.name ||
null,
discordAvatar: discordIdentity?.identity_data?.avatar_url || null,
discordEmail: discordIdentity?.identity_data?.email || null,
authSuccess,
error,
};
Expand Down
9 changes: 5 additions & 4 deletions www/components/settings/SecuritySettings.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { User } from '@supabase/supabase-js';
import { SettingsForm } from './SettingsForm';

interface User {
id: string;
email: string;
interface SecuritySettingsProps {
user: User | null;
}

export function SecuritySettings({ user }: { user: User }) {
export function SecuritySettings({ user }: SecuritySettingsProps) {
if (!user) return <div>Please log in to view security settings.</div>;
return (
<div className="space-y-4">
<h2 className="text-3xl font-bold text-primary">Security Settings</h2>
Expand Down
36 changes: 15 additions & 21 deletions www/components/settings/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useState, useEffect } from 'react';
import { createClient } from '@/utils/supabase/client';
import { User } from '@supabase/supabase-js';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
Expand All @@ -15,15 +16,6 @@ import {
} from '@/components/ui/card';
import Swal from 'sweetalert2';

interface User {
id: string;
email: string;
user_metadata?: {
full_name?: string;
avatar_url?: string;
};
}

interface SettingsFormProps {
user: User | null | undefined;
type: 'account' | 'security';
Expand Down Expand Up @@ -182,18 +174,6 @@ export function SettingsForm({ user, type }: SettingsFormProps) {
Save
</Button>
</div>
<div className="space-y-2">
<Label htmlFor="email" className="text-foreground">
Email
</Label>
<Input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="bg-input text-foreground flex-grow"
/>
</div>
</>
)}
{type === 'security' && (
Expand Down Expand Up @@ -238,6 +218,20 @@ export function SettingsForm({ user, type }: SettingsFormProps) {
)}
</CardContent>
<CardFooter className="flex justify-start border-t pt-6">
{type === 'account' && (
<div className="space-y-2">
<Label htmlFor="email" className="text-foreground">
Email
</Label>
<Input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="bg-input text-foreground flex-grow"
/>
</div>
)}
<Button
onClick={
type === 'account' ? handleEmailChange : handlePasswordChange
Expand Down
Loading

0 comments on commit a3e7488

Please sign in to comment.