diff --git a/packages/dashboard/src/components/Layout.js b/packages/dashboard/src/components/Layout.js index b9cebf39..4968629f 100644 --- a/packages/dashboard/src/components/Layout.js +++ b/packages/dashboard/src/components/Layout.js @@ -136,13 +136,11 @@ export default function Layout({ title, children }) { Settings - - Payments (coming soon) - + {/* + + Payments + + */} - - Payments (coming soon) - + {/* + + Payments + + */} { + res.json(user); +}; diff --git a/packages/dashboard/src/pages/api/stubs/user.json b/packages/dashboard/src/pages/api/stubs/user.json new file mode 100644 index 00000000..3b591617 --- /dev/null +++ b/packages/dashboard/src/pages/api/stubs/user.json @@ -0,0 +1,5 @@ +{ + "sub": "ab776d6d-f324-4fa7-a728-7587d5215481", + "tier": 1, + "subscribedUntil": "0001-01-01T00:00:00Z" +} diff --git a/packages/dashboard/src/pages/api/stubs/user/downloads.js b/packages/dashboard/src/pages/api/stubs/user/downloads.js index a364a381..c4a24c03 100644 --- a/packages/dashboard/src/pages/api/stubs/user/downloads.js +++ b/packages/dashboard/src/pages/api/stubs/user/downloads.js @@ -1,5 +1,4 @@ -// import items from "./downloads.json"; -const items = []; +import items from "./downloads.json"; export default (req, res) => { const offset = parseInt(req.query?.offset ?? 0, 10); diff --git a/packages/dashboard/src/pages/api/stubs/user/stats.js b/packages/dashboard/src/pages/api/stubs/user/stats.js new file mode 100644 index 00000000..81a65545 --- /dev/null +++ b/packages/dashboard/src/pages/api/stubs/user/stats.js @@ -0,0 +1,5 @@ +import stats from "./stats.json"; + +export default (req, res) => { + res.json(stats); +}; diff --git a/packages/dashboard/src/pages/api/stubs/user/stats.json b/packages/dashboard/src/pages/api/stubs/user/stats.json new file mode 100644 index 00000000..29696ca2 --- /dev/null +++ b/packages/dashboard/src/pages/api/stubs/user/stats.json @@ -0,0 +1,13 @@ +{ + "storageUsed": 809500672, + "numRegReads": 0, + "numRegWrites": 0, + "numUploads": 13, + "numDownloads": 78, + "totalUploadsSize": 618649028, + "totalDownloadsSize": 32307956843, + "bwUploads": 2810183680, + "bwDownloads": 32323934976, + "bwRegReads": 0, + "bwRegWrites": 0 +} diff --git a/packages/dashboard/src/pages/index.js b/packages/dashboard/src/pages/index.js index d0bd884a..c7f6b0d5 100644 --- a/packages/dashboard/src/pages/index.js +++ b/packages/dashboard/src/pages/index.js @@ -92,7 +92,7 @@ function SkylinkList({ items = [] }) { } export default function Home() { - const { data: user } = useSWR("/user", fetcher); + const { data: stats } = useSWR(`${apiPrefix}/user/stats`, fetcher); const { data: downloads } = useSWR(`${apiPrefix}/user/downloads?pageSize=3&offset=0`, fetcher); const { data: uploads } = useSWR(`${apiPrefix}/user/uploads?pageSize=3&offset=0`, fetcher); @@ -155,7 +155,7 @@ export default function Home() {
Storage used
-
{prettyBytes(user?.storageUsed ?? 0)}
+
{prettyBytes(stats?.storageUsed ?? 0)}
@@ -190,7 +190,7 @@ export default function Home() {
Bandwidth used
-
{prettyBytes(user?.bandwidthUsed ?? 0)}
+
{prettyBytes(stats?.bwDownloads ?? 0)}
diff --git a/packages/dashboard/src/pages/payments.js b/packages/dashboard/src/pages/payments.js index 78f96697..f61e0a8c 100644 --- a/packages/dashboard/src/pages/payments.js +++ b/packages/dashboard/src/pages/payments.js @@ -1,14 +1,19 @@ -import Link from "next/link"; +import dayjs from "dayjs"; import Layout from "../components/Layout"; import useSWR from "swr"; -const apiPrefix = process.env.NODE_ENV === "development" ? "/api/stubs" : "/api"; +const plans = [ + { id: "initial_free", name: "Free", price: 0, description: "Unlimited bandwidth with throttled speed" }, + { id: "initial_plus", name: "Skynet Plus", price: 5, description: "1 TB premium bandwidth with full speed" }, + { id: "initial_pro", name: "Skynet Pro", price: 20, description: "5 TB premium bandwidth with full speed" }, + { id: "initial_extreme", name: "Skynet Extreme", price: 80, description: "20 TB premium bandwidth with full speed" }, +]; +const currentlyActivePlan = "initial_free"; + const fetcher = (url) => fetch(url).then((r) => r.json()); export default function Payments() { - const { data: invoices, error } = useSWR(`${apiPrefix}/square/invoices`, fetcher); - - console.log(invoices); + const { data: invoices, error } = useSWR("/api/square/invoices", fetcher); return ( @@ -19,12 +24,12 @@ export default function Payments() {
Current plan
-
Free Plan
+
Free
-
Next invoice
+
Current payment
@@ -36,135 +41,6 @@ export default function Payments() { -
-
-
-
-
-

- Payment details -

-

- Update your billing information. Please note that updating your location could affect your tax - rates. -

-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
- -
-
-
-
{/* Plan */}
@@ -176,129 +52,55 @@ export default function Payments() { Plan -
- - help me choose a plan - -
Pricing plans
    -
  • - {/* On: "bg-orange-50 border-orange-200 z-10", Off: "border-gray-200" */} -
    - -

    - {/* On: "text-orange-900", Off: "text-gray-900" */} - + {plans.map((plan, index) => ( +

  • + {/* On: "bg-orange-50 border-orange-200 z-10", Off: "border-gray-200" */} +
    + +

    + {/* On: "text-orange-900", Off: "text-gray-900" */} + {plan.price ? `$${plan.price} / mo` : "no cost"} + {/* On: "text-orange-700", Off: "text-gray-500" */} + {/* ($290 / yr) */} +

    {/* On: "text-orange-700", Off: "text-gray-500" */} - {/* ($290 / yr) */} -

    - {/* On: "text-orange-700", Off: "text-gray-500" */} -

    - Unlimited bandwidth with throttled speed -

    -
    -
  • -
  • - {/* On: "bg-orange-50 border-orange-200 z-10", Off: "border-gray-200" */} -
    - -

    - {/* On: "text-orange-900", Off: "text-gray-900" */} - $5 / mo - {/* On: "text-orange-700", Off: "text-gray-500" */} ($50 / yr) -

    - {/* On: "text-orange-700", Off: "text-gray-500" */} -

    - 1 TB premium bandwidth with full speed -

    -
    -
  • -
  • - {/* On: "bg-orange-50 border-orange-200 z-10", Off: "border-gray-200" */} -
    - -

    - {/* On: "text-orange-900", Off: "text-gray-900" */} - $20 / mo - {/* On: "text-orange-700", Off: "text-gray-500" */} ($200 / yr) -

    - {/* On: "text-orange-700", Off: "text-gray-500" */} -

    - 5 TB premium bandwidth with full speed -

    -
    -
  • -
  • - {/* On: "bg-orange-50 border-orange-200 z-10", Off: "border-gray-200" */} -
    - -

    - {/* On: "text-orange-900", Off: "text-gray-900" */} - $80 / mo - {/* On: "text-orange-700", Off: "text-gray-500" */} ($800 / yr) -

    - {/* On: "text-orange-700", Off: "text-gray-500" */} -

    - 20 TB premium bandwidth with full speed -

    -
    -
  • +

    + {plan.description} +

    + + + ))}
- {/* Enabled: "bg-orange-500", Not Enabled: "bg-gray-200" */} - - - Annual billing - (Save 10%) + Currently active plan: + Free + + (next payment $5 on 10/10/2020 -{" "} + + cancel + + )
@@ -307,7 +109,7 @@ export default function Payments() { type="submit" className="bg-gray-800 border border-transparent rounded-md shadow-sm py-2 px-4 inline-flex justify-center text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-900" > - Save + Subscribe to selected plan @@ -334,6 +136,12 @@ export default function Payments() { > Date + + Invoice + - Amount + Status {/* `relative` is added here due to a weird bug in Safari that causes `sr-only` headings to introduce overflow on the body on mobile. @@ -358,19 +166,29 @@ export default function Payments() { - - 1/1/2020 - - Business Plan - Annual Billing - - CA$109.00 - - - View receipt - - - - {/* More items... */} + {invoices && + invoices.map((invoice) => ( + + + {dayjs(invoice.createdAt).format("DD/MM/YYYY")} + + + {invoice.invoiceNumber} + + {invoice.title} + {invoice.status} + + + View invoice + + + + ))}