Skip to content
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

RFC/refactor: code-split ui package #234

Merged
merged 8 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions core/app/(user)/forgot/ForgotForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use client";
import React, { FormEvent, useState } from "react";
import { Button, Icon } from "ui";
import { Button } from "ui/button";
import { Loader2 } from "ui/icon";

import { supabase } from "lib/supabase";
import { useEnvContext } from "next-runtime-env";


export default function ForgotForm() {
const { NEXT_PUBLIC_PUBPUB_URL } = useEnvContext()
const { NEXT_PUBLIC_PUBPUB_URL } = useEnvContext();

const [email, setEmail] = useState("");
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -50,9 +51,7 @@ export default function ForgotForm() {

<Button variant="outline" type="submit" disabled={!email || isLoading}>
Send password reset email
{isLoading && (
<Icon.Loader2 className="h-4 w-4 ml-4 animate-spin" />
)}
{isLoading && <Loader2 className="h-4 w-4 ml-4 animate-spin" />}
</Button>

{failure && (
Expand Down
4 changes: 2 additions & 2 deletions core/app/(user)/login/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import React, { useState, FormEvent } from "react";
import { Button } from "ui";
import { Button } from "ui/button";
import { supabase } from "lib/supabase";
import Link from "next/link";
import { useRouter } from "next/navigation";
Expand Down Expand Up @@ -38,7 +38,7 @@ export default function LoginForm() {
router.push("/settings");
}
}
}
};

return (
<div className="border p-4">
Expand Down
5 changes: 3 additions & 2 deletions core/app/(user)/reset/ResetForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import React, { useState, FormEvent } from "react";
import { Button, Icon } from "ui";
import { Button } from "ui/button";
import { Loader2 } from "ui/icon";
import { formatSupabaseError, supabase } from "lib/supabase";
import { useRouter } from "next/navigation";

Expand Down Expand Up @@ -57,7 +58,7 @@ export default function ResetForm() {

<Button variant="outline" type="submit" disabled={!password || isLoading}>
Set new password
{isLoading && <Icon.Loader2 className="h-4 w-4 ml-4 animate-spin" />}
{isLoading && <Loader2 className="h-4 w-4 ml-4 animate-spin" />}
</Button>

{error && (
Expand Down
6 changes: 4 additions & 2 deletions core/app/(user)/settings/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { supabase } from "lib/supabase";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { FormEvent, useState } from "react";
import { Avatar, AvatarFallback, AvatarImage, Button, Icon } from "ui";
import { Button } from "ui/button";
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
import { Loader2 } from "ui/icon";
import LogoutButton from "~/app/components/LogoutButton";
import { UserPutBody, UserSettings } from "~/lib/types";
import { useEnvContext } from "next-runtime-env";
Expand Down Expand Up @@ -162,7 +164,7 @@ export default function SettingsForm({
{!resetSuccess && (
<Button onClick={resetPassword} disabled={resetIsLoading}>
Send password reset email
{resetIsLoading && <Icon.Loader2 className="h-4 w-4 ml-4 animate-spin" />}
{resetIsLoading && <Loader2 className="h-4 w-4 ml-4 animate-spin" />}
</Button>
)}
{resetSuccess && (
Expand Down
2 changes: 1 addition & 1 deletion core/app/(user)/signup/SignupForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import React, { useState, FormEvent } from "react";
import { Button } from "ui";
import { Button } from "ui/button";
import { UserPostBody } from "~/lib/types";

export default function SignupForm() {
Expand Down
9 changes: 3 additions & 6 deletions core/app/InitClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ import { useEffect } from "react";
import { REFRESH_NAME, TOKEN_NAME } from "lib/auth/cookies";
import { createBrowserSupabase, supabase } from "lib/supabase";
import { usePathname } from "next/navigation";
import { useEnvContext } from 'next-runtime-env';
import { useEnvContext } from "next-runtime-env";

export default function InitClient() {
const { NEXT_PUBLIC_SUPABASE_PUBLIC_KEY , NEXT_PUBLIC_SUPABASE_URL } = useEnvContext();
const { NEXT_PUBLIC_SUPABASE_PUBLIC_KEY, NEXT_PUBLIC_SUPABASE_URL } = useEnvContext();

const pathname = usePathname();
useEffect(() => {
const isLocalhost = window.location.origin.includes("localhost");
const securityValue = isLocalhost ? "secure" : "";
createBrowserSupabase(
NEXT_PUBLIC_SUPABASE_URL,
NEXT_PUBLIC_SUPABASE_PUBLIC_KEY
);
createBrowserSupabase(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_PUBLIC_KEY);
supabase.auth.onAuthStateChange(async (event, session) => {
if (event === "SIGNED_OUT") {
// delete cookies on sign out
Expand Down
6 changes: 2 additions & 4 deletions core/app/c/[communitySlug]/CommunitySwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import Link from "next/link";
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
import {
Avatar,
AvatarFallback,
AvatarImage,
DropdownMenu,
DropdownMenuItem,
DropdownMenuContent,
DropdownMenuTrigger,
} from "ui";
} from "ui/dropdown-menu";
import { CommunityData } from "./layout";

type Props = {
Expand Down
7 changes: 5 additions & 2 deletions core/app/c/[communitySlug]/LoginSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getLoginData } from "~/lib/auth/loginData";
import { Avatar, AvatarFallback, AvatarImage, Button } from "ui";
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
import { Button } from "ui/button";
import LogoutButton from "../../components/LogoutButton";
import Link from "next/link";

Expand Down Expand Up @@ -27,7 +28,9 @@ export default async function LoginSwitcher() {
<div className="mt-1 flex flex-row items-">
<LogoutButton />
<Link className="ml-2" href="/settings">
<Button variant="outline" size="sm">Settings</Button>
<Button variant="outline" size="sm">
Settings
</Button>
</Link>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion core/app/c/[communitySlug]/integrations/IntegrationsList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import NextLink from "next/link";
import { Button, Card, CardContent, CardHeader } from "ui";

import { Button } from "ui/button";
import { Card, CardContent, CardHeader } from "ui/card";
import { IntegrationData } from "./page";
import { Row, RowContent, RowFooter } from "~/app/components/Row";

Expand Down
2 changes: 1 addition & 1 deletion core/app/c/[communitySlug]/pubs/PubHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from "next/link";
import { Button } from "ui";
import { Button } from "ui/button";

type Props = {};

Expand Down
18 changes: 5 additions & 13 deletions core/app/c/[communitySlug]/pubs/[pubId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { Prisma, PubField, PubFieldSchema, PubValue } from "@prisma/client";
import { AnySchema, JSONSchemaType } from "ajv";
import Link from "next/link";
import {
Avatar,
AvatarFallback,
AvatarImage,
Button,
CardContent,
CardHeader,
CardTitle,
HoverCard,
HoverCardContent,
HoverCardTrigger,
Separator,
} from "ui";
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
import { Button } from "ui/button";
import { CardContent, CardHeader, CardTitle } from "ui/card";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "ui/hover-card";
import { Separator } from "ui/separator";

import IntegrationActions from "~/app/components/IntegrationActions";
import { PubTitle } from "~/app/components/PubTitle";
Expand Down
20 changes: 6 additions & 14 deletions core/app/c/[communitySlug]/stages/components/Assign.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
"use client";
import Image from "next/image";
import React from "react";
import {
Button,
Card,
CardContent,
CardFooter,
CardTitle,
Dialog,
DialogContent,
DialogTrigger,
Popover,
PopoverContent,
PopoverTrigger,
useToast,
} from "ui";
import { Button } from "ui/button";
import { Card, CardContent, CardFooter, CardTitle } from "ui/card";
import { Dialog, DialogContent, DialogTrigger } from "ui/dialog";
import { Popover, PopoverContent, PopoverTrigger } from "ui/popover";
import { useToast } from "ui/use-toast";

import {
PermissionPayloadUser,
PubPayload,
Expand Down
4 changes: 3 additions & 1 deletion core/app/c/[communitySlug]/stages/components/Move.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";
import { Button, Popover, PopoverContent, PopoverTrigger, useToast } from "ui";
import { Button } from "ui/button";
import { useToast } from "ui/use-toast";
import { Popover, PopoverContent, PopoverTrigger } from "ui/popover";
import { PubPayload, StagePayload, StagePayloadMoveConstraintDestination } from "~/lib/types";
import { move } from "./lib/actions";

Expand Down
2 changes: 1 addition & 1 deletion core/app/c/[communitySlug]/stages/components/StageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Link from "next/link";
import { Fragment } from "react";
import { Button } from "ui";
import { Button } from "ui/button";
import PubRow from "~/app/components/PubRow";
import { getPubUsers } from "~/lib/permissions";
import { StagesById, StagePayload, UserLoginData } from "~/lib/types";
Expand Down
3 changes: 2 additions & 1 deletion core/app/c/[communitySlug]/stages/manage/StageEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";
import { Tabs, TabsContent, TabsList, TabsTrigger, toast } from "ui";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui/tabs";
import { toast } from "ui/use-toast";
import { StageFormSchema, moveConstraintSourcesForStage } from "~/lib/stages";
import { DeepPartial, StagesById, StagePayload } from "~/lib/types";
import StageForm from "./StageForm";
Expand Down
8 changes: 4 additions & 4 deletions core/app/c/[communitySlug]/stages/manage/StageForm.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useCallback, useEffect } from "react";
import { useForm } from "react-hook-form";
import { Button } from "ui/button";
import {
Button,
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
Icon,
Input,
} from "ui";
} from "ui/form";
import * as Icon from "ui/icon";
import { Input } from "ui/input";
import { assert } from "utils";
import { StageFormSchema } from "~/lib/stages";
import { StagePayload, StagesById, DeepPartial } from "~/lib/types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { useState } from "react";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui/tabs";
import StageEditor from "./StageEditor";
import { StagePayload, StagesById } from "~/lib/types";

Expand Down
3 changes: 2 additions & 1 deletion core/app/c/[communitySlug]/types/TypeBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { useState } from "react";
import { Button, Card, CardContent } from "ui";
import { Button } from "ui/button";
import { Card, CardContent } from "ui/card";
import { TypesData } from "./page";

type Props = { type: NonNullable<TypesData>[number] };
Expand Down
2 changes: 1 addition & 1 deletion core/app/components/IntegrationActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Popover, PopoverTrigger, Button, PopoverContent } from "ui";
import { Button } from "ui/button";
import { PubPayload } from "~/lib/types";

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion core/app/components/LogoutButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { supabase } from "~/lib/supabase";
import { Button } from "ui";
import { Button } from "ui/button";
import { useRouter } from "next/navigation";

export default function LogoutButton() {
Expand Down
8 changes: 6 additions & 2 deletions core/app/components/PubRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import Link from "next/link";
import React, { Fragment } from "react";
import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from "ui";
import { Button } from "ui/button";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "ui/collapsible";
import { cn } from "utils";
import { PubPayload } from "~/lib/types";
import IntegrationActions from "./IntegrationActions";
Expand Down Expand Up @@ -48,7 +49,10 @@ const ChildHierarchy = ({ pub }: { pub: PubPayload["children"][number] }) => {
<span className="text-gray-500 mr-2 font-semibold">
{group.pubType.name}
</span>
<Link href={`/pubs/${child.id}`} className="text-sm hover:underline">
<Link
href={`/pubs/${child.id}`}
className="text-sm hover:underline"
>
{getTitle(child)}
</Link>
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/app/components/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { PropsWithChildren } from "react";
import { Card, CardContent, CardFooter, CardHeader } from "ui";
import { Card, CardContent, CardFooter, CardHeader } from "ui/card";
import { cn } from "utils";

type Props = PropsWithChildren<{ className?: string }>;
Expand Down
14 changes: 7 additions & 7 deletions core/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Toaster } from "ui";
import { Toaster } from "ui/toaster";
import "ui/styles.css";
import InitClient from "./InitClient";
import { PublicEnvProvider } from 'next-runtime-env';
import { PublicEnvProvider } from "next-runtime-env";
import "./globals.css";

export const metadata = {
Expand All @@ -13,11 +13,11 @@ export default function RootLayout({ children }: { children: React.ReactNode })
return (
<html lang="en">
<body>
<PublicEnvProvider>
<InitClient />
{children}
<Toaster />
</PublicEnvProvider>
<PublicEnvProvider>
<InitClient />
{children}
<Toaster />
</PublicEnvProvider>
</body>
</html>
);
Expand Down
3 changes: 2 additions & 1 deletion core/lib/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const createBrowserSupabase = (url, publicKey) => {
});
};

export const formatSupabaseError = (error: AuthError) => `${error.name} ${error.status}: ${error.message}`
export const formatSupabaseError = (error: AuthError) =>
`${error.name} ${error.status}: ${error.message}`;
2 changes: 1 addition & 1 deletion core/scripts/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { randomUUID } from "crypto";
import { unJournalId } from "../prisma/exampleCommunitySeeds/unjournal";

const getServerSupabase = () => {
// can use the process.env here, because this code only runs in server context
// can use the process.env here, because this code only runs in server context
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const key = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!url || !key) {
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/terraform/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Dependencies

### State file bucket/config

You must have some way of storing terraform state files.
We use and recommend the s3 backend, but you can change
that configuration. In order to keep this code generic, however,
Expand All @@ -24,7 +25,6 @@ If you need to change the backend, update this file and `init` again.
the module exposes its configuration area, but those configurations
need to be supplied at plan/apply time using the flag `-var-file=demo-env.tfvars`.


## Adding secrets

To provide secrets to ECS containers, you should put them in AWS Secrets Manager.
Expand Down
Loading