Skip to content

Commit

Permalink
tidy things up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Sep 21, 2023
1 parent 8e1848f commit 30171c6
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/routes/_seo+/robots[.]txt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { generateRobotsTxt } from '@nasa-gcn/remix-seo'
import { type DataFunctionArgs } from '@remix-run/node'
import { getDomainUrl } from '#app/utils/misc.tsx'

export function loader({ request }: DataFunctionArgs) {
const origin = new URL(request.url).origin
return generateRobotsTxt([
{ type: 'sitemap', value: `${origin}/sitemap.xml` },
{ type: 'sitemap', value: `${getDomainUrl(request)}/sitemap.xml` },
])
}
8 changes: 5 additions & 3 deletions app/routes/_seo+/sitemap[.]xml.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { generateSitemap } from '@nasa-gcn/remix-seo'
// @ts-expect-error - this does work, though it's not exactly a public API
import { routes } from '@remix-run/dev/server-build'
import { type LoaderFunctionArgs } from '@remix-run/node'
import { type DataFunctionArgs } from '@remix-run/node'
import { getDomainUrl } from '#app/utils/misc.tsx'

export function loader({ request }: LoaderFunctionArgs) {
export function loader({ request }: DataFunctionArgs) {
return generateSitemap(request, routes, {
siteUrl: new URL(request.url).origin,
siteUrl: getDomainUrl(request),
headers: {
'Cache-Control': `public, max-age=${60 * 5}`,
},
Expand Down
5 changes: 5 additions & 0 deletions app/routes/admin+/cache.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import {
Form,
Expand Down Expand Up @@ -28,6 +29,10 @@ import {
} from '#app/utils/misc.tsx'
import { requireUserWithRole } from '#app/utils/permissions.ts'

export const handle: SEOHandle = {
getSitemapEntries: () => null,
}

export async function loader({ request }: DataFunctionArgs) {
await requireUserWithRole(request, 'admin')
const searchParams = new URL(request.url).searchParams
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.change-email.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { conform, useForm } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import * as E from '@react-email/components'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import { Form, useActionData, useLoaderData } from '@remix-run/react'
Expand All @@ -19,9 +20,11 @@ import { invariant, useIsPending } from '#app/utils/misc.tsx'
import { redirectWithToast } from '#app/utils/toast.server.ts'
import { EmailSchema } from '#app/utils/user-validation.ts'
import { verifySessionStorage } from '#app/utils/verification.server.ts'
import { type BreadcrumbHandle } from './profile.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="envelope-closed">Change Email</Icon>,
getSitemapEntries: () => null,
}

const newEmailAddressSessionKey = 'new-email-address'
Expand Down
7 changes: 5 additions & 2 deletions app/routes/settings+/profile.connections.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
json,
type DataFunctionArgs,
Expand All @@ -17,17 +18,19 @@ import { requireUserId } from '#app/utils/auth.server.ts'
import { resolveConnectionData } from '#app/utils/connections.server.ts'
import {
ProviderConnectionForm,
ProviderName,
type ProviderName,
ProviderNameSchema,
providerIcons,
providerNames,
} from '#app/utils/connections.tsx'
import { prisma } from '#app/utils/db.server.ts'
import { invariantResponse } from '#app/utils/misc.tsx'
import { createToastHeaders } from '#app/utils/toast.server.ts'
import { type BreadcrumbHandle } from './profile.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="link-2">Connections</Icon>,
getSitemapEntries: () => null,
}

async function userCanDeleteConnections(userId: string) {
Expand Down
5 changes: 5 additions & 0 deletions app/routes/settings+/profile.index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { conform, useForm } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import { Link, useFetcher, useLoaderData } from '@remix-run/react'
import { z } from 'zod'
Expand All @@ -18,6 +19,10 @@ import { sessionStorage } from '#app/utils/session.server.ts'
import { NameSchema, UsernameSchema } from '#app/utils/user-validation.ts'
import { twoFAVerificationType } from './profile.two-factor.tsx'

export const handle: SEOHandle = {
getSitemapEntries: () => null,
}

const ProfileFormSchema = z.object({
name: NameSchema.optional(),
username: UsernameSchema,
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.password.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { conform, useForm } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import { Form, Link, useActionData } from '@remix-run/react'
import { z } from 'zod'
Expand All @@ -16,9 +17,11 @@ import { prisma } from '#app/utils/db.server.ts'
import { useIsPending } from '#app/utils/misc.tsx'
import { redirectWithToast } from '#app/utils/toast.server.ts'
import { PasswordSchema } from '#app/utils/user-validation.ts'
import { type BreadcrumbHandle } from './profile.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="dots-horizontal">Password</Icon>,
getSitemapEntries: () => null,
}

const ChangePasswordForm = z
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.password_.create.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { conform, useForm } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import { Form, Link, useActionData } from '@remix-run/react'
import { z } from 'zod'
Expand All @@ -11,9 +12,11 @@ import { getPasswordHash, requireUserId } from '#app/utils/auth.server.ts'
import { prisma } from '#app/utils/db.server.ts'
import { useIsPending } from '#app/utils/misc.tsx'
import { PasswordSchema } from '#app/utils/user-validation.ts'
import { type BreadcrumbHandle } from './profile.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="dots-horizontal">Password</Icon>,
getSitemapEntries: () => null,
}

const CreatePasswordForm = z
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.photo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { conform, useForm } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
json,
redirect,
Expand All @@ -23,9 +24,11 @@ import {
useDoubleCheck,
useIsPending,
} from '#app/utils/misc.tsx'
import { type BreadcrumbHandle } from './profile.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="avatar">Photo</Icon>,
getSitemapEntries: () => null,
}

const MAX_SIZE = 1024 * 1024 * 3 // 3MB
Expand Down
9 changes: 7 additions & 2 deletions app/routes/settings+/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, type DataFunctionArgs } from '@remix-run/node'
import { Link, Outlet, useMatches } from '@remix-run/react'
import { z } from 'zod'
Expand All @@ -8,8 +9,12 @@ import { prisma } from '#app/utils/db.server.ts'
import { cn, invariantResponse } from '#app/utils/misc.tsx'
import { useUser } from '#app/utils/user.ts'

export const handle = {
export const BreadcrumbHandle = z.object({ breadcrumb: z.any() })
export type BreadcrumbHandle = z.infer<typeof BreadcrumbHandle>

export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="file-text">Edit Profile</Icon>,
getSitemapEntries: () => null,
}

export async function loader({ request }: DataFunctionArgs) {
Expand All @@ -23,7 +28,7 @@ export async function loader({ request }: DataFunctionArgs) {
}

const BreadcrumbHandleMatch = z.object({
handle: z.object({ breadcrumb: z.any() }),
handle: BreadcrumbHandle,
})

export default function EditUserProfile() {
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.two-factor.disable.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, type DataFunctionArgs } from '@remix-run/node'
import { useFetcher } from '@remix-run/react'
import { Icon } from '#app/components/ui/icon.tsx'
Expand All @@ -7,10 +8,12 @@ import { requireUserId } from '#app/utils/auth.server.ts'
import { prisma } from '#app/utils/db.server.ts'
import { useDoubleCheck } from '#app/utils/misc.tsx'
import { redirectWithToast } from '#app/utils/toast.server.ts'
import { type BreadcrumbHandle } from './profile.tsx'
import { twoFAVerificationType } from './profile.two-factor.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="lock-open-1">Disable</Icon>,
getSitemapEntries: () => null,
}

export async function loader({ request }: DataFunctionArgs) {
Expand Down
5 changes: 5 additions & 0 deletions app/routes/settings+/profile.two-factor.index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { generateTOTP } from '@epic-web/totp'
import { SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import { Link, useFetcher, useLoaderData } from '@remix-run/react'
import { Icon } from '#app/components/ui/icon.tsx'
Expand All @@ -8,6 +9,10 @@ import { prisma } from '#app/utils/db.server.ts'
import { twoFAVerificationType } from './profile.two-factor.tsx'
import { twoFAVerifyVerificationType } from './profile.two-factor.verify.tsx'

export const handle: SEOHandle = {
getSitemapEntries: () => null,
}

export async function loader({ request }: DataFunctionArgs) {
const userId = await requireUserId(request)
const verification = await prisma.verification.findUnique({
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.two-factor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { Outlet } from '@remix-run/react'
import { Icon } from '#app/components/ui/icon.tsx'
import { type VerificationTypes } from '#app/routes/_auth+/verify.tsx'
import { type BreadcrumbHandle } from './profile.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="lock-closed">2FA</Icon>,
getSitemapEntries: () => null,
}

export const twoFAVerificationType = '2fa' satisfies VerificationTypes
Expand Down
5 changes: 4 additions & 1 deletion app/routes/settings+/profile.two-factor.verify.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { conform, useForm } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { getTOTPAuthUri } from '@epic-web/totp'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import {
Form,
Expand All @@ -18,10 +19,12 @@ import { requireUserId } from '#app/utils/auth.server.ts'
import { prisma } from '#app/utils/db.server.ts'
import { getDomainUrl, useIsPending } from '#app/utils/misc.tsx'
import { redirectWithToast } from '#app/utils/toast.server.ts'
import { type BreadcrumbHandle } from './profile.tsx'
import { twoFAVerificationType } from './profile.two-factor.tsx'

export const handle = {
export const handle: BreadcrumbHandle & SEOHandle = {
breadcrumb: <Icon name="check">Verify</Icon>,
getSitemapEntries: () => null,
}

const VerifySchema = z.object({
Expand Down
2 changes: 0 additions & 2 deletions public/robots.txt

This file was deleted.

0 comments on commit 30171c6

Please sign in to comment.