-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Ecommerce client management #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2b31c13
feat: add link to header - placeholder commit
bassgeta 332e6d5
feat: initial scaffolding for ecommerce manage page
bassgeta 19877f5
feat: add display of clientids and creation
bassgeta 3e7d742
feat: use ecommerce client instead of client id for naming, implement…
bassgeta fb78fc8
fix: wording
bassgeta af3b005
feat: code review align and harden form validation
bassgeta f1a0c93
feat: migration script
bassgeta 744e1e0
feat: rename default client to Request Checkout
bassgeta e05fd96
feat: add client payment schema and webhook handling of payments
bassgeta e920d26
feat: implement ecommerce sales page
bassgeta 77a7575
feat: scaffold fetching of user receipts
bassgeta 3dd4070
refactor: use the DB ecommerce client id instead of the API one for c…
bassgeta a41867b
feat: implement table of receipts
bassgeta 54d39a3
feat: code review align and generate migration
bassgeta 99b1775
feat: add link to header - placeholder commit
bassgeta f192df1
feat: initial scaffolding for ecommerce manage page
bassgeta b688754
feat: add display of clientids and creation
bassgeta a2a34bb
feat: use ecommerce client instead of client id for naming, implement…
bassgeta 2e29272
fix: wording
bassgeta 4d50549
feat: code review align and harden form validation
bassgeta 1e4920a
feat: migration script
bassgeta ff3c2df
feat: rename default client to Request Checkout
bassgeta 2b60636
fix: mismerge issues
bassgeta 7f3b82c
fix: ecommerce link colours
bassgeta 258e817
fix: validate required fields on the webhook body before saving it to…
bassgeta bef6a6f
fix: unique index for webhooks
bassgeta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { BackgroundWrapper } from "@/components/background-wrapper"; | ||
import { EcommerceNavigation } from "@/components/ecommerce/ecommerce-navigation"; | ||
import { Footer } from "@/components/footer"; | ||
import { Header } from "@/components/header"; | ||
import { getCurrentSession } from "@/server/auth"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function EcommerceLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const { user } = await getCurrentSession(); | ||
if (!user) redirect("/"); | ||
|
||
return ( | ||
<BackgroundWrapper | ||
topGradient={{ from: "orange-100", to: "orange-200" }} | ||
bottomGradient={{ from: "zinc-100", to: "zinc-200" }} | ||
> | ||
<Header user={user} /> | ||
<main className="flex-grow flex flex-col w-full max-w-sm sm:max-w-2xl md:max-w-4xl lg:max-w-6xl xl:max-w-[72rem] mx-auto px-4 sm:px-6 lg:px-8 py-8 z-10"> | ||
<h1 className="mb-2 text-4xl font-bold tracking-tight">Ecommerce</h1> | ||
<p className="mb-8 text-lg text-muted-foreground"> | ||
Create and manage your ecommerce clients and view sales | ||
</p> | ||
<EcommerceNavigation /> | ||
{children} | ||
</main> | ||
<Footer /> | ||
</BackgroundWrapper> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { EcommerceManage } from "@/components/ecommerce/manage"; | ||
import { getCurrentSession } from "@/server/auth"; | ||
import { api } from "@/trpc/server"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function ManagePage() { | ||
const { user } = await getCurrentSession(); | ||
|
||
if (!user) { | ||
redirect("/"); | ||
} | ||
|
||
const ecommerceClients = await api.ecommerce.getAll.query(); | ||
|
||
return <EcommerceManage initialEcommerceClients={ecommerceClients} />; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { redirect } from "next/navigation"; | ||
|
||
export default function EcommercePage() { | ||
redirect("/ecommerce/manage"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getCurrentSession } from "@/server/auth"; | ||
//import { api } from "@/trpc/server"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function SalesPage() { | ||
const { user } = await getCurrentSession(); | ||
|
||
if (!user) { | ||
redirect("/"); | ||
} | ||
|
||
// TODO fetch sales data | ||
|
||
return <div>Sales Page - to be implemented</div>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client"; | ||
|
||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
import Link from "next/link"; | ||
import { usePathname } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export function EcommerceNavigation() { | ||
const pathname = usePathname(); | ||
const [activeTab, setActiveTab] = useState("manage"); | ||
|
||
useEffect(() => { | ||
if (pathname.includes("/sales")) { | ||
setActiveTab("sales"); | ||
} else { | ||
setActiveTab("manage"); | ||
} | ||
}, [pathname]); | ||
|
||
return ( | ||
<Tabs value={activeTab} className="w-full mb-8"> | ||
<TabsList className="grid w-full grid-cols-3"> | ||
<TabsTrigger value="manage" asChild> | ||
<Link href="/ecommerce/manage">Manage</Link> | ||
</TabsTrigger> | ||
<TabsTrigger value="sales" asChild> | ||
<Link href="/ecommerce/sales">Sales</Link> | ||
</TabsTrigger> | ||
</TabsList> | ||
</Tabs> | ||
); | ||
bassgeta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Input } from "@/components/ui/input"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { Loader2 } from "lucide-react"; | ||
import { useForm } from "react-hook-form"; | ||
import { | ||
type EcommerceClientFormValues, | ||
ecommerceClientFormSchema, | ||
} from "./types"; | ||
|
||
interface EcommerceClientFormProps { | ||
onSubmit: (data: EcommerceClientFormValues) => void; | ||
isLoading?: boolean; | ||
defaultValues?: Partial<EcommerceClientFormValues>; | ||
submitButtonText?: string; | ||
onCancel?: () => void; | ||
} | ||
|
||
export function EcommerceClientForm({ | ||
onSubmit, | ||
isLoading = false, | ||
defaultValues, | ||
submitButtonText = "Create Client ID", | ||
onCancel, | ||
}: EcommerceClientFormProps) { | ||
const form = useForm<EcommerceClientFormValues>({ | ||
resolver: zodResolver(ecommerceClientFormSchema), | ||
defaultValues: { | ||
label: "", | ||
domain: "", | ||
feeAddress: undefined, | ||
feePercentage: undefined, | ||
...defaultValues, | ||
}, | ||
}); | ||
bassgeta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> | ||
<FormField | ||
control={form.control} | ||
name="label" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Label</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="My Ecommerce Store" | ||
disabled={isLoading} | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<FormField | ||
control={form.control} | ||
name="domain" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Domain</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="https://mystore.com" | ||
disabled={isLoading} | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<FormField | ||
control={form.control} | ||
name="feeAddress" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Fee Address (Optional)</FormLabel> | ||
<FormControl> | ||
<Input | ||
placeholder="0x..." | ||
className="font-mono" | ||
disabled={isLoading} | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<FormField | ||
control={form.control} | ||
name="feePercentage" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Fee Percentage (Optional)</FormLabel> | ||
<FormControl> | ||
<Input | ||
type="number" | ||
placeholder="5" | ||
min="0" | ||
max="100" | ||
step="0.1" | ||
disabled={isLoading} | ||
value={field.value || ""} | ||
onChange={(e) => | ||
field.onChange( | ||
e.target.value ? Number(e.target.value) : undefined, | ||
) | ||
} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<div className="flex justify-end gap-2 pt-4"> | ||
{onCancel && ( | ||
<Button | ||
type="button" | ||
variant="outline" | ||
onClick={onCancel} | ||
disabled={isLoading} | ||
> | ||
Cancel | ||
</Button> | ||
)} | ||
<Button type="submit" disabled={isLoading}> | ||
{isLoading ? ( | ||
<> | ||
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
{submitButtonText.includes("Create") | ||
? "Creating..." | ||
: "Updating..."} | ||
</> | ||
) : ( | ||
submitButtonText | ||
)} | ||
</Button> | ||
</div> | ||
</form> | ||
</Form> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.