Skip to content

Commit

Permalink
chore: remove sample email flag
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersuweijie committed Oct 23, 2024
1 parent 3b991e6 commit 1026bd2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/app/src/app/edit/[[...slug]]/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { submit } from "./action";
import { Entry } from "@prisma/client";
import { EntryForm } from "@/components/entry-form";

export default function Content({entry, sampleEmail}: {entry: Entry, sampleEmail: string}) {
export default function Content({entry}: {entry: Entry, sampleEmail: string}) {
return (
<div className="w-full py-20 lg:py-40">
<div className="container mx-auto">
Expand All @@ -13,7 +13,7 @@ export default function Content({entry, sampleEmail}: {entry: Entry, sampleEmail
<h1 className="text-xl md:text-3xl tracking-tighter text-left font-extrabold">Edit pattern</h1>
<h1 className="text-md md:text-xl tracking-tighter text-left">{entry.title}</h1>
<h1 className="text-md md:text-xl tracking-tighter text-left">{entry.description}</h1>
<EntryForm entry={entry} onFormSubmit={submit} sampleEmailFlag={sampleEmail ? true : false} />
<EntryForm entry={entry} onFormSubmit={submit} />
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/app/submit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { z } from 'zod';
import { createEntry } from './action';
import { formSchema } from './form';

export default function Submit({searchParams: {sampleEmail}}: {searchParams: {sampleEmail: string}}) {
export default function Submit() {

const [modal, setModal] = useState<boolean>(false);
const [modalMessage, setModalMessage] = useState<string>("");
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function Submit({searchParams: {sampleEmail}}: {searchParams: {sa
<div className="flex text-left justify-center items-center gap-4 flex-col px-10 md:px-40">
<h1 className="text-xl md:text-3xl tracking-tighter text-left font-extrabold">Submit new pattern</h1>
<Button className="mb-6" variant="secondary" size="sm" onClick={fillDemo}>Fill form using a sample</Button>
<EntryForm entry={entry} onFormSubmit={onSubmit} sampleEmailFlag={sampleEmail ? true : false}/>
<EntryForm entry={entry} onFormSubmit={onSubmit}/>
</div>
</div>
</div>
Expand Down
45 changes: 21 additions & 24 deletions packages/app/src/components/entry-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { processEmail, ProcessEmailResult } from "@/app/submit/email/action";
interface EntryFormProps {
onFormSubmit: (values: z.infer<typeof formSchema>) => void,
entry?: Entry,
sampleEmailFlag?: boolean,
}

interface Email {
Expand All @@ -28,7 +27,7 @@ interface Email {
subject: string,
}

export function EntryForm({ onFormSubmit, entry, sampleEmailFlag }: EntryFormProps) {
export function EntryForm({ onFormSubmit, entry }: EntryFormProps) {

const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -644,29 +643,27 @@ export function EntryForm({ onFormSubmit, entry, sampleEmailFlag }: EntryFormPro
</div>
)
})}
{sampleEmailFlag && (
<div className="flex flex-col">
<div className="flex flex-row items-center">
<b>Select a sample email</b>
<Input className='ml-2 mr-4' type="file" onChange={e => uploadEmail(e)} />
<Button type="button" onClick={process} disabled={!email || isProcessingEmail}>{isProcessingEmail ? "Processing..." : "Process"}</Button>
</div>
{(processedResult && email) && <div className="mt-4">
{processedResult && processedResult.error && <p className="text-red-500">{processedResult.message}</p>}
{processedResult && !processedResult.error && <div className="mt-4">
<p>{processedResult.message}</p>
<p><b>Matched Data:</b></p>
{processedResult.matches.map((v, i) => {
return <p className="ml-4" key={i}><b>{v.name}:</b> {v.match}</p>
})}
<p><b>Calculated Parameters:</b> <a className="text-blue-500" onClick={setProcessedParameters} href="#">Click to update the pattern above</a></p>
{Object.keys(processedResult.parameters || {}).map((v, i) => {
return <p className="ml-4" key={i}><b>{v}:</b> {(processedResult.parameters as any)[v] ?? "N/A"}</p>
})}
</div>}
</div>}
<div className="flex flex-col">
<div className="flex flex-row items-center">
<b>Select a sample email</b>
<Input className='ml-2 mr-4' type="file" onChange={e => uploadEmail(e)} />
<Button type="button" onClick={process} disabled={!email || isProcessingEmail}>{isProcessingEmail ? "Processing..." : "Process"}</Button>
</div>
)}
{(processedResult && email) && <div className="mt-4">
{processedResult && processedResult.error && <p className="text-red-500">{processedResult.message}</p>}
{processedResult && !processedResult.error && <div className="mt-4">
<p>{processedResult.message}</p>
<p><b>Matched Data:</b></p>
{processedResult.matches.map((v, i) => {
return <p className="ml-4" key={i}><b>{v.name}:</b> {v.match}</p>
})}
<p><b>Calculated Parameters:</b> <a className="text-blue-500" onClick={setProcessedParameters} href="#">Click to update the pattern above</a></p>
{Object.keys(processedResult.parameters || {}).map((v, i) => {
return <p className="ml-4" key={i}><b>{v}:</b> {(processedResult.parameters as any)[v] ?? "N/A"}</p>
})}
</div>}
</div>}
</div>
<div className="flex flex-col items-center">
<Button type="submit" size="lg" onClick={form.handleSubmit(onFormSubmit)} >Submit</Button>
</div>
Expand Down

0 comments on commit 1026bd2

Please sign in to comment.