diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index acf6edd..d02443e 100755 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -21,9 +21,15 @@ // Check for user session on mount (this is a placeholder, actual implementation may vary) onMount(() => { const storedUserString = localStorage.getItem('user'); - if (storedUserString) { + const token = localStorage.getItem('auth_token'); + if (storedUserString && token) { storedUser = JSON.parse(storedUserString); user.set(storedUser); + } else { + // Clear if inconsistent + localStorage.removeItem('user'); + localStorage.removeItem('auth_token'); + user.set(null); } }); @@ -39,6 +45,7 @@ const logout = () => { user.set(null); localStorage.removeItem('user'); + localStorage.removeItem('auth_token'); window.location.href = '/'; }; diff --git a/src/routes/(app)/[stateSlug]/+page.svelte b/src/routes/(app)/[stateSlug]/+page.svelte index 7fba1ed..35ae47b 100755 --- a/src/routes/(app)/[stateSlug]/+page.svelte +++ b/src/routes/(app)/[stateSlug]/+page.svelte @@ -1,42 +1,84 @@
-

Vendor Dashboard

+

Vendor Dashboard

{#if successMessage} @@ -175,10 +263,91 @@
{/if} -

Welcome to the Vendor section. Navigate to specific pages using the links below.

-
- Profile - Price + +
+
+ {#if companyLoading} +
+ +
+ {:else if companyError} +
+ {companyError} +
+ {:else if company} +
+ +
+
+
+ + {company.name.charAt(0).toUpperCase()} + +
+
+
+ + +
+

{company.name}

+
+ {#if company.address} +
+ Address:
+ {company.address} +
+ {/if} + {#if company.town && company.state} +
+ Location:
+ {company.town}, {company.state} +
+ {/if} + {#if company.phone} + + {/if} + {#if company.owner_name} +
+ Owner:
+ {company.owner_name} +
+ {/if} + {#if company.owner_phone_number} + + {/if} + {#if company.email} +
+ Email:
+ {company.email} +
+ {/if} +
+ Member Since:
+ {new Date(company.created).toLocaleDateString()} +
+
+
+
+ {:else} +
+

No Company Profile Found

+

Create your company profile to get started.

+ Create Company Profile +
+ {/if} +
+
+ + +
+ Company Profile + Create Listing
@@ -196,7 +365,7 @@ {:else if listings.length === 0}

No listings found.. create one :)

- Create Listing + Create Listing
{:else}
@@ -204,6 +373,7 @@ Company + Location Price Card Price Cash Min Order @@ -218,6 +388,13 @@ {#each listings as listing} {listing.company_name} + + {#if listing.town} + {listing.town} (ID: {listing.county_id}) + {:else} + County ID: {listing.county_id} + {/if} + diff --git a/src/routes/(app)/vendor/price/+page.svelte b/src/routes/(app)/vendor/listing/+page.svelte similarity index 87% rename from src/routes/(app)/vendor/price/+page.svelte rename to src/routes/(app)/vendor/listing/+page.svelte index 476c6a8..b081ac7 100644 --- a/src/routes/(app)/vendor/price/+page.svelte +++ b/src/routes/(app)/vendor/listing/+page.svelte @@ -19,7 +19,8 @@ bioPercent: 0, phone: '', state: '', - countyId: 0 + countyId: 0, + town: '' }; // Active status @@ -39,7 +40,9 @@ bioPercent: '', phone: '', state: '', - countyId: '' + countyId: '', + minimumOrder: '', + town: '' }; // Form submission state @@ -76,6 +79,8 @@ errors.phone = ''; errors.state = ''; errors.countyId = ''; + errors.minimumOrder = ''; + errors.town = ''; let isValid = true; @@ -110,6 +115,16 @@ isValid = false; } + if (formData.minimumOrder === null || formData.minimumOrder < 1) { + errors.minimumOrder = 'Minimum order must be at least 1'; + isValid = false; + } + + if (!formData.town.trim()) { + errors.town = 'Town is required'; + isValid = false; + } + return isValid; } @@ -140,7 +155,8 @@ bio_percent: formData.bioPercent, phone: formData.phone, online_ordering: onlineOrdering, - county_id: formData.countyId + county_id: formData.countyId, + town: formData.town.trim() || null }) }); @@ -196,7 +212,7 @@ @@ -320,10 +336,16 @@ min="1" max="200" step="1" - class="input input-bordered w-full" + required + class="input input-bordered w-full {errors.minimumOrder ? 'input-error' : ''}" bind:value={formData.minimumOrder} - placeholder="Optional (1-200)" + placeholder="Enter minimum order quantity" /> + {#if errors.minimumOrder} + + {/if}
@@ -347,51 +369,10 @@ - +
-

Contact & Location

+

Location

- -
- - - {#if errors.phone} - - {/if} -
- - -
-
- Online Ordering - - - -
-
-
{/if}
+ + +
+ + + {#if errors.town} + + {/if} + +
+
+
+ + +
+

Contact

+
+ +
+ + + {#if errors.phone} + + {/if} +
+ + +
+
+ Online Ordering + + + +
+
diff --git a/src/routes/(app)/vendor/price/[id]/+page.svelte b/src/routes/(app)/vendor/listing/[id]/+page.svelte similarity index 88% rename from src/routes/(app)/vendor/price/[id]/+page.svelte rename to src/routes/(app)/vendor/listing/[id]/+page.svelte index 67d2680..6fd7183 100644 --- a/src/routes/(app)/vendor/price/[id]/+page.svelte +++ b/src/routes/(app)/vendor/listing/[id]/+page.svelte @@ -23,6 +23,7 @@ phone: string | null; online_ordering: string; county_id: number; + town: string | null; user_id: number; last_edited: string; } @@ -41,7 +42,8 @@ bioPercent: 0, phone: '', state: '', - countyId: 0 + countyId: 0, + town: '' }; // Active status @@ -61,7 +63,9 @@ bioPercent: '', phone: '', state: '', - countyId: '' + countyId: '', + minimumOrder: '', + town: '' }; // Form submission state @@ -76,7 +80,7 @@ // Load existing listing data async function loadListing() { try { - const token = localStorage.getItem('token'); + const token = localStorage.getItem('auth_token'); const response = await fetch(`http://localhost:9552/listing/${listingId}`, { headers: { 'Authorization': token ? `Bearer ${token}` : '' @@ -97,6 +101,7 @@ formData.phone = listing.phone || ''; onlineOrdering = listing.online_ordering; formData.countyId = listing.county_id; + formData.town = listing.town || ''; // Load the state for this county await loadStateForCounty(listing.county_id); @@ -158,6 +163,8 @@ errors.phone = ''; errors.state = ''; errors.countyId = ''; + errors.minimumOrder = ''; + errors.town = ''; let isValid = true; @@ -192,6 +199,16 @@ isValid = false; } + if (formData.minimumOrder === null || formData.minimumOrder < 1) { + errors.minimumOrder = 'Minimum order must be at least 1'; + isValid = false; + } + + if (!formData.town.trim()) { + errors.town = 'Town is required'; + isValid = false; + } + return isValid; } @@ -205,7 +222,7 @@ submitMessage = ''; try { - const token = localStorage.getItem('token'); + const token = localStorage.getItem('auth_token'); const response = await fetch(`http://localhost:9552/listing/${listingId}`, { method: 'PUT', headers: { @@ -222,7 +239,8 @@ bio_percent: formData.bioPercent, phone: formData.phone, online_ordering: onlineOrdering, - county_id: formData.countyId + county_id: formData.countyId, + town: formData.town.trim() || null }) }); @@ -282,7 +300,7 @@ @@ -411,10 +429,16 @@ min="1" max="200" step="1" - class="input input-bordered w-full" + required + class="input input-bordered w-full {errors.minimumOrder ? 'input-error' : ''}" bind:value={formData.minimumOrder} - placeholder="Optional (1-200)" + placeholder="Enter minimum order quantity" /> + {#if errors.minimumOrder} + + {/if} @@ -438,51 +462,10 @@ - +
-

Contact & Location

+

Location

- -
- - - {#if errors.phone} - - {/if} -
- - -
-
- Online Ordering - - - -
-
-
{/if}
+ + +
+ + + {#if errors.town} + + {/if} + +
+
+
+ + +
+

Contact

+
+ +
+ + + {#if errors.phone} + + {/if} +
+ + +
+
+ Online Ordering + + + +
+
diff --git a/src/routes/(app)/vendor/profile/+page.svelte b/src/routes/(app)/vendor/profile/+page.svelte index f9bd03e..94ca13b 100644 --- a/src/routes/(app)/vendor/profile/+page.svelte +++ b/src/routes/(app)/vendor/profile/+page.svelte @@ -23,7 +23,7 @@ try { const response = await fetch('http://localhost:9552/company', { headers: { - 'Authorization': `Bearer ${localStorage.getItem('token')}` + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` } }); @@ -67,7 +67,7 @@ method: 'PUT', headers: { 'Content-Type': 'application/json', - 'Authorization': `Bearer ${localStorage.getItem('token')}` + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` }, body: JSON.stringify(payload) }); @@ -105,7 +105,7 @@ const response = await fetch('http://localhost:9552/company', { method: 'DELETE', headers: { - 'Authorization': `Bearer ${localStorage.getItem('token')}` + 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` } }); @@ -128,7 +128,7 @@ } onMount(() => { - const token = localStorage.getItem('token'); + const token = localStorage.getItem('auth_token'); if (token) { fetchCompany(); } else {