-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into example-34ht
- Loading branch information
Showing
18 changed files
with
876 additions
and
939 deletions.
There are no files selected for viewing
This file contains 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
93 changes: 5 additions & 88 deletions
93
dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx
This file contains 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 |
---|---|---|
@@ -1,102 +1,19 @@ | ||
import { fetchInvoiceById, fetchAllCustomers } from '@/app/lib/data'; | ||
import { updateInvoice } from '@/app/lib/actions'; | ||
import { fetchInvoiceById, fetchCustomerNames } from '@/app/lib/data'; | ||
import { notFound } from 'next/navigation'; | ||
import Form from '@/app/ui/invoices/edit-form'; | ||
|
||
export default async function Page({ params }: { params: { id: string } }) { | ||
const id = params.id; | ||
const invoice = await fetchInvoiceById(id); | ||
const customers = await fetchAllCustomers(); | ||
const customerNames = await fetchCustomerNames(); | ||
|
||
if (!invoice) { | ||
notFound(); | ||
} | ||
|
||
return ( | ||
<main role="main"> | ||
<div className="mx-auto max-w-sm rounded-lg border px-6 py-8 shadow-sm"> | ||
<h2 | ||
className="mb-6 text-xl font-semibold text-gray-900" | ||
role="heading" | ||
aria-level={2} | ||
> | ||
Edit Invoice | ||
</h2> | ||
<form action={updateInvoice}> | ||
<input type="hidden" name="id" value={id} /> | ||
{/* Customer selection */} | ||
<div className="mb-4" role="group"> | ||
<label | ||
htmlFor="customer" | ||
className="mb-2 block text-sm font-semibold" | ||
> | ||
Customer | ||
</label> | ||
<select | ||
id="customer" | ||
name="customerId" | ||
className="block w-full rounded-md border-0 py-1.5 pl-3 text-sm ring-1 ring-inset ring-gray-200 placeholder:text-gray-200 focus:ring-blue-200" | ||
defaultValue={invoice.name} | ||
aria-label="Select Customer" | ||
> | ||
{customers.map((customer) => ( | ||
<option key={customer.id} value={customer.id}> | ||
{customer.name} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
|
||
{/* Invoice amount */} | ||
<div className="mb-4" role="group"> | ||
<label className="mb-2 block text-sm font-semibold">Amount</label> | ||
<div className="relative mt-2 rounded-md shadow-sm"> | ||
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"> | ||
<span className="text-gray-600 sm:text-sm" aria-hidden="true"> | ||
$ | ||
</span> | ||
</div> | ||
<input | ||
name="amount" | ||
type="number" | ||
step="0.01" | ||
defaultValue={invoice.amount} | ||
placeholder="00.00" | ||
className="block w-full rounded-md border-0 py-1.5 pl-7 text-sm leading-6 ring-1 ring-inset ring-gray-200 placeholder:text-gray-400 focus:ring-blue-200" | ||
aria-label="Enter Amount" | ||
/> | ||
</div> | ||
</div> | ||
|
||
{/* Invoice status */} | ||
<div className="mb-4" role="group"> | ||
<label | ||
className="mb-2 block text-sm font-semibold" | ||
htmlFor="status" | ||
> | ||
Status | ||
</label> | ||
<select | ||
id="status" | ||
name="status" | ||
className="block w-full rounded-md border-0 py-1.5 pl-3 text-sm ring-1 ring-inset ring-gray-200 placeholder:text-gray-200 focus:ring-blue-200" | ||
defaultValue={invoice.status} | ||
aria-label="Select Status" | ||
> | ||
<option value="pending">Pending</option> | ||
<option value="paid">Paid</option> | ||
</select> | ||
</div> | ||
|
||
{/* Submit button */} | ||
<button | ||
type="submit" | ||
className="rounded-md bg-blue-500 px-4 py-2 text-center text-sm font-semibold text-white hover:bg-blue-600 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2" | ||
aria-label="Update Invoice" | ||
> | ||
Update Invoice | ||
</button> | ||
</form> | ||
</div> | ||
<main> | ||
<Form invoice={invoice} customerNames={customerNames} id={id} /> | ||
</main> | ||
); | ||
} |
101 changes: 6 additions & 95 deletions
101
dashboard/15-final/app/dashboard/invoices/create/page.tsx
This file contains 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 |
---|---|---|
@@ -1,101 +1,12 @@ | ||
import { createInvoice } from '@/app/lib/actions'; | ||
import { fetchAllCustomers } from '@/app/lib/data'; | ||
import { fetchCustomerNames } from '@/app/lib/data'; | ||
import Form from '@/app/ui/invoices/create-form'; | ||
|
||
export default async function Page() { | ||
const customers = await fetchAllCustomers(); | ||
const customerNames = await fetchCustomerNames(); | ||
|
||
return ( | ||
<div className="mx-auto max-w-sm rounded-lg border px-6 py-8 shadow-sm"> | ||
<h2 className="mb-6 text-xl font-semibold text-gray-900"> | ||
Create Invoice | ||
</h2> | ||
|
||
<form action={createInvoice}> | ||
{/* Customer */} | ||
<div className="mb-4"> | ||
<label | ||
htmlFor="customer" | ||
className="mb-2 block text-sm font-semibold" | ||
aria-label="Select Customer" | ||
> | ||
Customer | ||
</label> | ||
<select | ||
id="customer" | ||
name="customerId" | ||
className="block w-full rounded-md border-0 py-1.5 pl-3 text-sm ring-1 ring-inset ring-gray-200 placeholder:text-gray-200" | ||
defaultValue="" | ||
aria-label="Select Customer" | ||
aria-required="true" | ||
required | ||
> | ||
<option value="" disabled> | ||
Select a customer | ||
</option> | ||
{customers.map((customer) => ( | ||
<option key={customer.id} value={customer.id}> | ||
{customer.name} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
|
||
{/* Amount */} | ||
<div className="mb-4"> | ||
<label | ||
className="mb-2 block text-sm font-semibold" | ||
htmlFor="amount" | ||
id="amount-label" | ||
> | ||
Amount | ||
</label> | ||
<div className="relative mt-2 rounded-md shadow-sm"> | ||
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"> | ||
<span className="text-gray-600 sm:text-sm" aria-hidden="true"> | ||
$ | ||
</span> | ||
</div> | ||
<input | ||
id="amount" | ||
name="amount" | ||
type="number" | ||
step="0.01" | ||
placeholder="00.00" | ||
className="block w-full rounded-md border-0 py-1.5 pl-7 text-sm leading-6 ring-1 ring-inset ring-gray-200 placeholder:text-gray-400" | ||
aria-describedby="amount-label" | ||
/> | ||
</div> | ||
</div> | ||
|
||
{/* Invoice Status */} | ||
<div className="mb-4"> | ||
<label | ||
className="mb-2 block text-sm font-semibold" | ||
htmlFor="status" | ||
id="status-label" | ||
> | ||
Status | ||
</label> | ||
<select | ||
id="status" | ||
name="status" | ||
className="block w-full rounded-md border-0 py-1.5 pl-3 text-sm ring-1 ring-inset ring-gray-200 placeholder:text-gray-200" | ||
defaultValue="pending" | ||
aria-describedby="status-label" | ||
> | ||
<option value="pending">Pending</option> | ||
<option value="paid">Paid</option> | ||
</select> | ||
</div> | ||
|
||
{/* Submit Button */} | ||
<button | ||
type="submit" | ||
className="rounded-md bg-blue-500 px-4 py-2 text-center text-sm font-semibold text-white hover:bg-blue-600 focus:border-blue-700 focus:outline-none focus:ring focus:ring-blue-200" | ||
> | ||
Create | ||
</button> | ||
</form> | ||
</div> | ||
<main> | ||
<Form customerNames={customerNames} /> | ||
</main> | ||
); | ||
} |
This file contains 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
Oops, something went wrong.