Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Enhance the profile™ (#269)

Sean Boult52ec9e2cb1f2
diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx
index 0b8224e1..515fe842 100644
--- a/src/app/settings/page.tsx
+++ b/src/app/settings/page.tsx
@@ -40,6 +40,7 @@ export default async function SettingsPage() {
bio: profileData.bio,
userLinks,
}}
+ username={profileData.name}
/>
);
}
diff --git a/src/components/settings/index.tsx b/src/components/settings/index.tsx
index eaacfd13..0aac0f72 100644
--- a/src/components/settings/index.tsx
+++ b/src/components/settings/index.tsx
@@ -1,16 +1,16 @@
'use client';
import { zodResolver } from '@hookform/resolvers/zod';
-import { Github, Link as LinkIcon, Linkedin, Twitter, Youtube } from 'lucide-react';
import { Controller, useFieldArray, useForm, useWatch } from 'react-hook-form';
import * as z from 'zod';
import { Button } from '../ui/button';
import { Form, FormItem } from '../ui/form';
import { Input } from '../ui/input';
import { RichMarkdownEditor } from '../ui/rich-markdown-editor';
-import { ToastAction } from '../ui/toast';
import { toast } from '../ui/use-toast';
import { updateProfile } from './settings.action';
+import Link from 'next/link';
+import { MagicIcon } from '../ui/magic-icon';
export interface UserLinkType {
id: string | null;
@@ -29,8 +29,14 @@ const formSchema = z.object({
export type FormSchema = z.infer<typeof formSchema>;
-export const Settings = ({ profileData }: { profileData: FormSchema }) => {
- const form = useForm<FormSchema>({
+export const Settings = ({
+ profileData,
+ username,
+}: {
+ profileData: FormSchema;
+ username: string;
+}) => {
+ const form = useForm < FormSchema > ({
resolver: zodResolver(formSchema),
defaultValues: {
...profileData,
@@ -61,16 +67,26 @@ export const Settings = ({ profileData }: { profileData: FormSchema }) => {
toast({
variant: 'success',
title: 'Your settings have been updated',
- action: <ToastAction altText="Settings updated">Settings updated</ToastAction>,
});
};
return (
<div className="container">
- <h2 className="mt-10 text-3xl font-bold">Profile</h2>
+ <div className="flex w-full justify-between mt-10">
+ <div className="mr-10">
+ <h2 className="text-3xl font-bold">Settings</h2>
+ <h4 className="text-xl font-bold mt-6 mb-4">Bio</h4>
+ </div>
+
+ <Link href={`@${username}`} className="mb-6">
+ <Button variant="outline" type="button">
+ View profile
+ </Button>
+ </Link>
+ </div>
+
<Form {...form}>
<form action={() => onSubmit(getValues())}>
- <h4 className="mb-4 text-xl">Tell us about yourself</h4>
<div className="h-[300px] w-[600px]">
<Controller
control={control}
@@ -110,14 +126,3 @@ export const Settings = ({ profileData }: { profileData: FormSchema }) => {
</div>
);
};
-
-function MagicIcon({ url }: { url: string }) {
- if (url.startsWith('https://github.com/')) return <Github className="h-5 w-5 text-neutral-400" />;
- if (url.startsWith('https://twitter.com/'))
- return <Twitter className="h-5 w-5 text-neutral-400" />;
- if (url.startsWith('https://linked.in/'))
- return <Linkedin className="h-5 w-5 text-neutral-400" />;
- if (url.startsWith('https://youtube.com/'))
- return <Youtube className="h-5 w-5 text-neutral-400" />;
- return <LinkIcon className="h-5 w-5 text-neutral-400" />;
-}
diff --git a/src/components/settings/settings.action.ts b/src/components/settings/settings.action.ts
index f9092972..f41a2a03 100644
--- a/src/components/settings/settings.action.ts
+++ b/src/components/settings/settings.action.ts
@@ -4,7 +4,7 @@ import { getServerSession } from 'next-auth';
import { prisma } from '~/server/db';
import { authOptions } from '~/server/auth';
-import type { FormSchema, UserLinkType } from '.';
+import type { FormSchema } from '.';
import { revalidatePath } from 'next/cache';
/**
diff --git a/src/components/ui/magic-icon.tsx b/src/components/ui/magic-icon.tsx
new file mode 100644
index 00000000..94e8a3e1
--- /dev/null
+++ b/src/components/ui/magic-icon.tsx
@@ -0,0 +1,14 @@
+import { Github, LinkIcon, Linkedin, Twitter, Youtube } from 'lucide-react';
+
+// TODO: this could be more robust
+// it's not accounting for subdomains like the boomer www and stuff
+export function MagicIcon({ url }: { url: string }) {
+ if (url.startsWith('https://github.com/')) return <Github className="h-5 w-5 text-neutral-400" />;
+ if (url.startsWith('https://twitter.com/'))
+ return <Twitter className="h-5 w-5 text-neutral-400" />;
+ if (url.startsWith('https://www.linkedin.com/'))
+ return <Linkedin className="h-5 w-5 text-neutral-400" />;
+ if (url.startsWith('https://youtube.com/'))
+ return <Youtube className="h-5 w-5 text-neutral-400" />;
+ return <LinkIcon className="h-5 w-5 text-neutral-400" />;
+}
diff --git a/src/components/user/dashboard/index.tsx b/src/components/user/dashboard/index.tsx
index f9bcfa6a..87d53913 100644
--- a/src/components/user/dashboard/index.tsx
+++ b/src/components/user/dashboard/index.tsx
@@ -7,14 +7,14 @@ import { SolutionsTab } from '../dashboard/solutions-tab';
import type { User } from '@prisma/client';
import { getRelativeTime } from '~/utils/relativeTime';
import { prisma } from '~/server/db';
-import ReportDialog from '~/components/report';
-import { ActionMenu } from '~/components/ui/action-menu';
import UserHeader from './user-header';
import { Button } from '~/components/ui/button';
import Link from 'next/link';
import { getServerSession } from 'next-auth';
import { authOptions } from '~/server/auth';
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
+import { MagicIcon } from '~/components/ui/magic-icon';
+import { stripProtocolAndWWW } from '~/utils/stringUtils';
interface Props {
// TODO: how do do this union type with just letting prisma halp
@@ -59,31 +59,35 @@ export default async function Dashboard({ user }: Props) {
return (
<div className="container">
- <div className="flex-1 space-y-4 pt-6">
- <div className="flex items-center gap-4">
- <div className="flex items-center space-x-2">
+ <div className="flex-1 space-y-4 mt-10">
+ <div className="flex gap-4">
+ <div className="flex pace-x-2">
<Image
className="rounded-3xl"
alt="user avatar"
width="100"
height="100"
- src="/avatar.jpeg"
+ src={user.image ?? '/avatar.jpeg'}
/>
</div>
- <div>
- <UserHeader user={user} />
- <p
- className="text-sm italic tracking-tight"
- title={`Joined ${user.createdAt.toString()}`}
- >
- Joined {getRelativeTime(user.createdAt)}
- </p>
+ <div className="flex w-full justify-between">
+ <div>
+ <UserHeader user={user} />
+ <p
+ className="text-sm italic tracking-tight"
+ title={`Joined ${user.createdAt.toString()}`}
+ >
+ Joined {getRelativeTime(user.createdAt)}
+ </p>
+ </div>
+ <div>
+ {session?.user.id === user.id && (
+ <Link href="/settings">
+ <Button variant="outline">Edit Profile</Button>
+ </Link>
+ )}
+ </div>
</div>
- {session?.user.id === user.id && (
- <Link href="/settings">
- <Button>Edit Profile</Button>
- </Link>
- )}
</div>
<div className="max-w-md">
@@ -91,17 +95,23 @@ export default async function Dashboard({ user }: Props) {
</div>
{user.userLinks.length > 0 && (
- <ol>
+ <div>
{user.userLinks
.filter((item) => item.url !== '')
.map((link) => (
- <li key={link.id}>
- <a href={link.url} target="_blank" rel="noopener noreferrer">
- {link.url}
+ <div className="flex gap-2" key={link.id}>
+ <MagicIcon url={link.url} />
+ <a
+ className="hover:text-zinc-400"
+ href={link.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ {stripProtocolAndWWW(link.url)}
</a>
- </li>
+ </div>
))}
- </ol>
+ </div>
)}
<Tabs defaultValue="in-progress" className="space-y-4">
diff --git a/src/utils/stringUtils.ts b/src/utils/stringUtils.ts
new file mode 100644
index 00000000..5bc1b735
--- /dev/null
+++ b/src/utils/stringUtils.ts
@@ -0,0 +1,8 @@
+/**
+ * Replace the protocol and www subdomain with empty string
+ * @example
+ * https://www.google.com => google.com
+ */
+export const stripProtocolAndWWW = (url: string) => {
+ return url.replace(/(^\w+:|^)\/\//, '').replace(/^www\./, '');
+};