Skip to content

Commit 71fe8a1

Browse files
committed
profile settings part 1
1 parent 621b27a commit 71fe8a1

File tree

10 files changed

+421
-39
lines changed

10 files changed

+421
-39
lines changed

bun.lock

Lines changed: 23 additions & 19 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@radix-ui/react-slot": "^1.2.3",
6161
"@radix-ui/react-switch": "^1.2.5",
6262
"@radix-ui/react-tabs": "^1.1.12",
63+
"@radix-ui/react-tooltip": "^1.2.7",
6364
"@react-email/components": "^0.0.41",
6465
"better-auth": "^1.2.8",
6566
"class-variance-authority": "^0.7.1",
@@ -77,6 +78,7 @@
7778
"react-hook-form": "^7.57.0",
7879
"sonner": "^2.0.5",
7980
"tailwind-merge": "^3.3.0",
81+
"use-debounce": "^10.0.5",
8082
"zod": "^3.25.51"
8183
},
8284
"devDependencies": {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { NextRequest } from "next/server";
2+
import { prisma } from "@/lib/database";
3+
import { auth } from "@/lib/auth";
4+
import { headers } from "next/headers";
5+
6+
export async function POST(request: NextRequest) {
7+
const { address } = await request.json();
8+
const session = await auth.api.getSession({
9+
headers: await headers()
10+
});
11+
12+
if (!address) {
13+
return Response.json({ status: "ERROR", message: "Invalid address data" }, { status: 400 });
14+
}
15+
if (!session || !session.user) {
16+
return Response.json({ status: "ERROR", message: "Unauthorized" }, { status: 401 });
17+
}
18+
19+
try {
20+
const result = await prisma.address.findFirst({ where: { userId: session.user.id } });
21+
if (result) {
22+
await prisma.address.update({
23+
where: { id: result.id },
24+
data: {
25+
street: address.street,
26+
suite: address.suite,
27+
zipcode: address.zipcode,
28+
city: address.city
29+
}
30+
});
31+
} else {
32+
await prisma.address.create({
33+
data: {
34+
user: { connect: { id: session.user.id } },
35+
street: address.street,
36+
suite: address.suite,
37+
zipcode: address.zipcode,
38+
city: address.city
39+
}
40+
});
41+
}
42+
43+
return Response.json({ status: "OK", address });
44+
} catch (error) {
45+
console.error("Error saving address:", error);
46+
return Response.json({ status: "ERROR", message: "Failed to save address" }, { status: 500 });
47+
}
48+
}
49+
50+
export async function GET(request: NextRequest) {
51+
const session = await auth.api.getSession({
52+
headers: await headers()
53+
});
54+
55+
if (!session || !session.user) {
56+
return Response.json({ status: "ERROR", message: "Unauthorized" }, { status: 401 });
57+
}
58+
59+
try {
60+
const address = await prisma.address.findFirst({
61+
where: { userId: session.user.id }
62+
});
63+
64+
if (!address) {
65+
return Response.json({
66+
status: "OK",
67+
address: {
68+
street: "",
69+
suite: "",
70+
postalCode: "",
71+
city: ""
72+
}
73+
});
74+
}
75+
76+
return Response.json({
77+
status: "OK",
78+
address: {
79+
street: address.street,
80+
suite: address.suite,
81+
zipCode: address.zipcode,
82+
city: address.city
83+
}
84+
});
85+
} catch (error) {
86+
console.error("Error fetching address:", error);
87+
return Response.json({ status: "ERROR", message: "Failed to fetch address" }, { status: 500 });
88+
}
89+
}

src/app/api/profile/company/route.ts

Whitespace-only changes.

src/app/profile/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ function Profile() {
7272
<div className="flex flex-col md:flex-row md:items-start gap-6 md:gap-8 lg:gap-10">
7373
<div className="w-full md:w-auto md:min-w-[260px] lg:min-w-[300px] flex flex-col gap-6 md:gap-8 mb-6 md:mb-0">
7474
<div className="flex items-center gap-4 p-2 md:p-0">
75-
<UserAvatar user={{ name: imie, image: null }} className="h-14 w-14 sm:h-16 sm:w-16" />
75+
<UserAvatar
76+
user={{ name: imie, image: null }}
77+
className="h-14 w-14 sm:h-16 sm:w-16"
78+
fallbackClassName="text-2xl"
79+
/>
7680
<div className="flex flex-col min-w-0">
7781
<span className="text-sm text-shadow-xs">Cześć,</span>
7882
<span className="text-lg sm:text-xl font-semibold text-red-700 leading-tight truncate">{imie}</span>

src/components/CartComponents/FormInput.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cn } from "@/lib/utils";
22
import { Label } from "@/components/ui/label";
3+
import clsx from "clsx";
34

45
interface FormInputProps {
56
label: string;
@@ -9,6 +10,7 @@ interface FormInputProps {
910
required?: boolean;
1011
className?: string;
1112
value?: string;
13+
disabled?: boolean;
1214
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
1315
}
1416

@@ -20,6 +22,7 @@ export default function FormInput({
2022
required = false,
2123
className = "",
2224
value,
25+
disabled = false,
2326
onChange
2427
}: FormInputProps) {
2528
return (
@@ -34,9 +37,13 @@ export default function FormInput({
3437
placeholder={placeholder}
3538
required={required}
3639
value={value}
40+
disabled={disabled}
3741
onChange={onChange}
38-
className="border border-stone-300 rounded-md p-2.5 text-sm focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors duration-200"
42+
className={clsx(
43+
disabled && "bg-stone-100 cursor-not-allowed",
44+
"border border-stone-300 rounded-md p-2.5 text-sm focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-colors duration-200"
45+
)}
3946
/>
4047
</div>
4148
);
42-
}
49+
}

src/components/CartContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export const CartProvider = ({
170170
);
171171
};
172172

173-
function deepEqual(obj1: { [x: string]: any } | null, obj2: { [x: string]: any } | null) {
173+
export function deepEqual(obj1: { [x: string]: any } | null, obj2: { [x: string]: any } | null) {
174174
if (obj1 === obj2) {
175175
return true;
176176
}

0 commit comments

Comments
 (0)