Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Use x button for the dialog (#173)

Sean Boult6a4ee472ca19
diff --git a/src/components/admin/reports.tsx b/src/components/admin/reports.tsx
index 0e0dc554..12c2a9ba 100644
--- a/src/components/admin/reports.tsx
+++ b/src/components/admin/reports.tsx
@@ -167,6 +167,7 @@ export const ReportDetails = ({ data }: ReportsProps) => {
})}
</TableBody>
</Table>
+ {/* // TODO: good first issue, dont use controlled state for this */}
<Dialog open={dialogOpen} onOpenChange={(e) => setDialogOpen(!e)}>
{/* max-w-xl is not the best solution, the dialog width need fixing with the markdown. */}
<DialogContent className="max-w-xl">
diff --git a/src/components/challenge/description/index.tsx b/src/components/challenge/description/index.tsx
index ffb5b286..7ae65f41 100644
--- a/src/components/challenge/description/index.tsx
+++ b/src/components/challenge/description/index.tsx
@@ -3,6 +3,7 @@
import { clsx } from 'clsx';
import { debounce } from 'lodash';
+import * as DialogPrimitive from '@radix-ui/react-dialog';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useRef, useState } from 'react';
@@ -78,8 +79,6 @@ export function Description({ challenge }: Props) {
}, 500),
).current;
- const [dialogOpen, setDialogOpen] = useState(false);
-
const form = useForm<FormValues>({
defaultValues: {
comments: '',
@@ -123,7 +122,6 @@ export function Description({ challenge }: Props) {
description: <p>Please log in to make this report.</p>,
});
}
- setDialogOpen(false);
} catch (e) {
toast({
title: 'Something went wrong.',
@@ -136,98 +134,99 @@ export function Description({ challenge }: Props) {
<>
<div className="flex items-baseline justify-between">
<TypographyH3 className="mb-2 font-medium">{challenge.name}</TypographyH3>
+ <Dialog>
+ <DialogTrigger>
+ <ActionMenu
+ items={[
+ {
+ key: 'feedback',
+ label: 'Feedback',
+ icon: 'Flag',
+ },
+ ]}
+ onChange={() => {
+ // do nothing
+ }}
+ />
+ </DialogTrigger>
- <ActionMenu
- items={[
- {
- key: 'feedback',
- label: 'Feedback',
- icon: 'Flag',
- },
- ]}
- onChange={() => setDialogOpen(true)}
- />
- </div>
-
- <Dialog open={dialogOpen} onOpenChange={(e) => setDialogOpen(!e)}>
- <DialogContent>
- <Form {...form}>
- {/* eslint-disable-next-line @typescript-eslint/no-misused-promises */}
- <form onSubmit={form.handleSubmit(onSubmit)}>
- <DialogHeader>
- <DialogTitle>Feedback: {challenge.name}</DialogTitle>
- </DialogHeader>
+ <DialogContent>
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)}>
+ <DialogHeader>
+ <DialogTitle>Feedback: {challenge.name}</DialogTitle>
+ </DialogHeader>
- <div className="my-4 flex flex-col gap-4">
- <TypographyLarge>Issues Encountered</TypographyLarge>
- <FormField
- name="examples"
- render={({ field }) => (
- <FormItem>
- <div className="flex items-center gap-4">
- <Checkbox
- id="examples"
- checked={field.value as boolean}
- onChange={field.onChange}
- onCheckedChange={field.onChange}
- />
- <label htmlFor="examples">
- Description or examples are unclear or incorrect
- </label>
- </div>
- </FormItem>
- )}
- />
- <FormField
- name="derogatory"
- render={({ field }) => (
- <FormItem>
- <div className="flex items-center gap-4">
- <Checkbox
- id="derogatory"
- checked={field.value as boolean}
- onCheckedChange={field.onChange}
- />
- <label htmlFor="derogatory">Racist or other derogatory statement</label>
- </div>
- </FormItem>
- )}
- />
- <FormField
- name="other"
- render={({ field }) => (
- <FormItem>
- <div className="flex items-center gap-4">
- <Checkbox
- id="other"
- checked={field.value as boolean}
- onCheckedChange={field.onChange}
- />
- <label htmlFor="other">Other</label>
- </div>
- </FormItem>
- )}
- />
- <FormField
- name="comments"
- render={({ field }) => (
- <FormItem>
- <TypographyLarge>Comments</TypographyLarge>
- <Textarea value={field.value as string} onChange={field.onChange} />
- </FormItem>
- )}
- />
- </div>
- <DialogFooter>
- <Button variant="secondary" type="button" onClick={() => setDialogOpen(false)}>
- Close
- </Button>
- <Button type="submit">Report</Button>
- </DialogFooter>
- </form>
- </Form>
- </DialogContent>
- </Dialog>
+ <div className="my-4 flex flex-col gap-4">
+ <TypographyLarge>Issues Encountered</TypographyLarge>
+ <FormField
+ name="examples"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center gap-4">
+ <Checkbox
+ id="examples"
+ checked={field.value as boolean}
+ onChange={field.onChange}
+ onCheckedChange={field.onChange}
+ />
+ <label htmlFor="examples">
+ Description or examples are unclear or incorrect
+ </label>
+ </div>
+ </FormItem>
+ )}
+ />
+ <FormField
+ name="derogatory"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center gap-4">
+ <Checkbox
+ id="derogatory"
+ checked={field.value as boolean}
+ onCheckedChange={field.onChange}
+ />
+ <label htmlFor="derogatory">Racist or other derogatory statement</label>
+ </div>
+ </FormItem>
+ )}
+ />
+ <FormField
+ name="other"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center gap-4">
+ <Checkbox
+ id="other"
+ checked={field.value as boolean}
+ onCheckedChange={field.onChange}
+ />
+ <label htmlFor="other">Other</label>
+ </div>
+ </FormItem>
+ )}
+ />
+ <FormField
+ name="comments"
+ render={({ field }) => (
+ <FormItem>
+ <TypographyLarge>Comments</TypographyLarge>
+ <Textarea value={field.value as string} onChange={field.onChange} />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter>
+ <DialogPrimitive.Close asChild>
+ <Button type="submit">Report</Button>
+ </DialogPrimitive.Close>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ </div>
<div className="mb-6 flex items-center gap-4">
<DifficultyBadge difficulty={challenge.difficulty} />
diff --git a/src/components/challenge/settings-form.tsx b/src/components/challenge/settings-form.tsx
index a24ca2f4..f85b6b68 100644
--- a/src/components/challenge/settings-form.tsx
+++ b/src/components/challenge/settings-form.tsx
@@ -23,6 +23,7 @@ import {
} from '~/components/ui/select';
import { useEditorSettingsStore } from './settings-store';
import { useToast } from '../ui/use-toast';
+import { DialogFooter } from '../ui/dialog';
const formSchema = z.object({
fontSize: z.string(),
@@ -133,9 +134,12 @@ export function SettingsForm() {
</FormItem>
)}
/>
- <DialogPrimitive.Close asChild>
- <Button type="submit">Submit</Button>
- </DialogPrimitive.Close>
+
+ <DialogFooter>
+ <DialogPrimitive.Close asChild>
+ <Button type="submit">Save</Button>
+ </DialogPrimitive.Close>
+ </DialogFooter>
</form>
</Form>
);
diff --git a/src/components/challenge/share-form.tsx b/src/components/challenge/share-form.tsx
index cba7c2bd..8ba67dea 100644
--- a/src/components/challenge/share-form.tsx
+++ b/src/components/challenge/share-form.tsx
@@ -2,6 +2,9 @@
import { useCallback, useState } from 'react';
import { Clipboard as ClipboardIcon, CheckCircle2 as CheckCircle2Icon } from 'lucide-react';
+import { Button } from '../ui/button';
+import * as DialogPrimitive from '@radix-ui/react-dialog';
+import { DialogFooter } from '../ui/dialog';
export function ShareForm() {
const url = window.location.href;
@@ -26,18 +29,21 @@ export function ShareForm() {
<div className="flex flex-col space-y-4">
<p>Copy this challenge url to share with your friends!</p>
<code className="rounded-md border px-4 py-2 dark:border-gray-300">{url}</code>
- <button
- className={`ml-auto mt-4 flex items-center justify-between space-x-2 rounded-lg px-3 py-2 duration-300 active:scale-75
+
+ <DialogFooter>
+ <button
+ className={`flex items-center justify-between space-x-2 rounded-lg px-2 py-1 duration-300 active:scale-75
${
copied
? 'border border-green-500 text-green-500 dark:border-green-700 dark:bg-green-700 dark:text-white'
: 'border border-gray-100 text-black hover:bg-gray-100 dark:bg-white'
}`}
- onClick={copyToClipboard}
- >
- <span>{copied ? 'Copied!' : 'Copy'}</span>
- {copied ? <CheckCircle2Icon /> : <ClipboardIcon />}
- </button>
+ onClick={copyToClipboard}
+ >
+ <span>{copied ? 'Copied!' : 'Copy'}</span>
+ {copied ? <CheckCircle2Icon /> : <ClipboardIcon />}
+ </button>
+ </DialogFooter>
</div>
);
}