Skip to content

Commit

Permalink
feat: change several routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrsxx committed Nov 8, 2023
1 parent e0be0de commit 6dbd4d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
File renamed without changes.
14 changes: 8 additions & 6 deletions src/app/(public)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { useState } from 'react';
import { useFormState } from 'react-dom';
import { z } from 'zod';
import { NEXT_PUBLIC_URL } from '@/lib/env';
import { URL_WITHOUT_PROTOCOL } from '@/lib/env';
import { Alert } from '@/components/ui/alert';
import { createLink } from '../actions';
import { validUrl } from '../schema';
import { Submit } from './submit';
import type { ChangeEvent } from 'react';

Expand All @@ -23,16 +23,18 @@ export default function Home(): JSX.Element {
target: { value }
}: ChangeEvent<HTMLInputElement>): void => setUrl(value);

const isValidURL = z.string().url().safeParse(url).success;
const isValidURL = validUrl.safeParse(url).success;

return (
<main>
<section className='mx-auto w-full max-w-md'>
<form className='grid gap-4' action={formAction}>
<div className='flex flex-col items-center gap-4 sm:flex-row'>
<p>{NEXT_PUBLIC_URL}/</p>
<div className='flex w-full items-center py-0 pr-0'>
<p className='custom-input rounded-r-none border-r-0 text-gray-600 dark:text-gray-300'>
{URL_WITHOUT_PROTOCOL}/
</p>
<input
className='custom-input w-full'
className='custom-input w-full rounded-l-none'
name='slug'
type='text'
value={slug}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Link from 'next/link';
import { redirect } from 'next/navigation';
import { checkSlugExists } from '@/lib/helper-server';
import { checkSlugExists } from '@/lib/helper';
import { NEXT_PUBLIC_URL } from '@/lib/env';
import { CopyButton } from '@/components/ui/copy-button';
import { Button } from '@/components/ui/button';

export default async function Success({
searchParams: { slug }
params: { slug }
}: {
searchParams: { slug: string };
params: { slug: string };
}): Promise<JSX.Element> {
const slugExists = await checkSlugExists(slug);

if (!slugExists) redirect('/');

const url = `${NEXT_PUBLIC_URL}/${slug}`;
const url = `${NEXT_PUBLIC_URL}/l/${slug}`;

return (
<main>
<section className='mx-auto grid w-full max-w-md gap-4'>
<h1>Your short link has been created successfully:</h1>
<div className='main-border relative rounded p-4'>
<div className='main-border relative rounded px-3 py-2'>
<a
className='animated-underline'
href={url}
Expand Down

0 comments on commit 6dbd4d3

Please sign in to comment.