Changes
This commit is contained in:
+21
-1
@@ -12,12 +12,14 @@ import { Save, Package } from "lucide-react";
|
|||||||
import { useShopifyProducts } from "@/hooks/useShopifyProducts";
|
import { useShopifyProducts } from "@/hooks/useShopifyProducts";
|
||||||
|
|
||||||
const profileSchema = z.object({
|
const profileSchema = z.object({
|
||||||
|
company_name: z.string().trim().max(100, { message: "Företagsnamn får max vara 100 tecken" }).optional(),
|
||||||
street_address: z.string().trim().max(200, { message: "Gatuadress får max vara 200 tecken" }).optional(),
|
street_address: z.string().trim().max(200, { message: "Gatuadress får max vara 200 tecken" }).optional(),
|
||||||
postal_code: z.string().trim().max(10, { message: "Postnummer får max vara 10 tecken" }).optional(),
|
postal_code: z.string().trim().max(10, { message: "Postnummer får max vara 10 tecken" }).optional(),
|
||||||
city: z.string().trim().max(100, { message: "Ort får max vara 100 tecken" }).optional(),
|
city: z.string().trim().max(100, { message: "Ort får max vara 100 tecken" }).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
interface ProfileData {
|
interface ProfileData {
|
||||||
|
company_name: string;
|
||||||
street_address: string;
|
street_address: string;
|
||||||
postal_code: string;
|
postal_code: string;
|
||||||
city: string;
|
city: string;
|
||||||
@@ -25,11 +27,13 @@ interface ProfileData {
|
|||||||
|
|
||||||
const Account = () => {
|
const Account = () => {
|
||||||
const [profile, setProfile] = useState<ProfileData>({
|
const [profile, setProfile] = useState<ProfileData>({
|
||||||
|
company_name: "",
|
||||||
street_address: "",
|
street_address: "",
|
||||||
postal_code: "",
|
postal_code: "",
|
||||||
city: "",
|
city: "",
|
||||||
});
|
});
|
||||||
const [originalProfile, setOriginalProfile] = useState<ProfileData>({
|
const [originalProfile, setOriginalProfile] = useState<ProfileData>({
|
||||||
|
company_name: "",
|
||||||
street_address: "",
|
street_address: "",
|
||||||
postal_code: "",
|
postal_code: "",
|
||||||
city: "",
|
city: "",
|
||||||
@@ -42,6 +46,7 @@ const Account = () => {
|
|||||||
const { products, isLoading: productsLoading } = useShopifyProducts("product_type:Abonnemang");
|
const { products, isLoading: productsLoading } = useShopifyProducts("product_type:Abonnemang");
|
||||||
|
|
||||||
const hasChanges =
|
const hasChanges =
|
||||||
|
profile.company_name !== originalProfile.company_name ||
|
||||||
profile.street_address !== originalProfile.street_address ||
|
profile.street_address !== originalProfile.street_address ||
|
||||||
profile.postal_code !== originalProfile.postal_code ||
|
profile.postal_code !== originalProfile.postal_code ||
|
||||||
profile.city !== originalProfile.city;
|
profile.city !== originalProfile.city;
|
||||||
@@ -61,7 +66,7 @@ const Account = () => {
|
|||||||
try {
|
try {
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from("profiles")
|
.from("profiles")
|
||||||
.select("street_address, postal_code, city")
|
.select("company_name, street_address, postal_code, city")
|
||||||
.eq("user_id", user!.id)
|
.eq("user_id", user!.id)
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
|
|
||||||
@@ -74,6 +79,7 @@ const Account = () => {
|
|||||||
});
|
});
|
||||||
} else if (data) {
|
} else if (data) {
|
||||||
const profileData = {
|
const profileData = {
|
||||||
|
company_name: data.company_name || "",
|
||||||
street_address: data.street_address || "",
|
street_address: data.street_address || "",
|
||||||
postal_code: data.postal_code || "",
|
postal_code: data.postal_code || "",
|
||||||
city: data.city || "",
|
city: data.city || "",
|
||||||
@@ -105,6 +111,7 @@ const Account = () => {
|
|||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from("profiles")
|
.from("profiles")
|
||||||
.update({
|
.update({
|
||||||
|
company_name: profile.company_name || null,
|
||||||
street_address: profile.street_address || null,
|
street_address: profile.street_address || null,
|
||||||
postal_code: profile.postal_code || null,
|
postal_code: profile.postal_code || null,
|
||||||
city: profile.city || null,
|
city: profile.city || null,
|
||||||
@@ -183,6 +190,19 @@ const Account = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="company_name">Företagsnamn</Label>
|
||||||
|
<Input
|
||||||
|
id="company_name"
|
||||||
|
type="text"
|
||||||
|
value={profile.company_name}
|
||||||
|
onChange={(e) =>
|
||||||
|
setProfile({ ...profile, company_name: e.target.value })
|
||||||
|
}
|
||||||
|
placeholder="Företagsnamn"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Label>Leveransadress</Label>
|
<Label>Leveransadress</Label>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user