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

Dashboard settings form QOL improvements #51

Merged
merged 4 commits into from
Jul 31, 2023
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
9 changes: 6 additions & 3 deletions src/app/dashboard/settings/settings-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ export default function SettingsForm({
)}
/>

<div>
<div className="inline-flex gap-x-4">
<CancelConfirmModal
setShow={setShowConfirmAlert}
show={showConfirmAlert}
reset={handleReset}
isDirty={formState.isDirty}
isDisabled={formState.isSubmitting || pending || !formState.isDirty}
/>

<Button type="submit" disabled={formState.isSubmitting || pending}>
<Button
type="submit"
disabled={formState.isSubmitting || pending || !formState.isDirty}
>
{formState.isSubmitting || pending ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Toaster } from "~/components/ui/toaster";
import { siteConfig } from "~/config/site";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });
const inter = Inter({ subsets: ["latin"], display: "swap" });

export const metadata: Metadata = {
title: {
Expand Down
11 changes: 3 additions & 8 deletions src/components/layout/cancel-confirm-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ interface CancelConfirmModalProps {
show: boolean;
setShow: (show: boolean) => void;
reset: () => void;
isDirty: boolean;
isDisabled: boolean;
}

export default function CancelConfirmModal({
show,
setShow,
reset,
isDirty,
isDisabled,
}: CancelConfirmModalProps) {
return (
<AlertDialog open={show} onOpenChange={setShow}>
<AlertDialogTrigger asChild>
<Button
variant="outline"
className="mr-4 text-destructive hover:text-destructive"
type="reset"
disabled={!isDirty}
>
<Button variant="destructive" type="reset" disabled={isDisabled}>
Cancel
</Button>
</AlertDialogTrigger>
Expand Down
5 changes: 3 additions & 2 deletions src/components/layout/image-upload-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { FileWithPath } from "react-dropzone";
import { useDropzone } from "react-dropzone";
import { type ControllerRenderProps } from "react-hook-form";
import { generateClientDropzoneAccept } from "uploadthing/client";
import { type SettingsValues } from "~/types";
import {
Dialog,
DialogContent,
Expand All @@ -18,6 +17,7 @@ import {
} from "~/components/ui/dialog";
import { useUploadThing } from "~/lib/uploadthing";
import { hasFileNameSpaces } from "~/lib/utils";
import { type SettingsValues } from "~/types";
import Icons from "../shared/icons";
import { Button } from "../ui/button";
import { toast } from "../ui/use-toast";
Expand Down Expand Up @@ -99,6 +99,7 @@ export default function ImageUploadModal({
<DialogTrigger asChild>
<div className="absolute left-0 top-0 flex h-28 w-28 cursor-pointer items-center justify-center rounded-full bg-primary/40 text-white opacity-0 group-hover:opacity-100 dark:bg-secondary/40">
<Button
type="button"
size="sm"
variant="ghost"
className="text-xs hover:bg-transparent hover:text-white"
Expand All @@ -123,7 +124,7 @@ export default function ImageUploadModal({
loading="lazy"
/>
</div>
<div className=" mt-10">
<div className="mt-10">
<Button
disabled={isUploading}
onClick={handleCancel}
Expand Down
13 changes: 2 additions & 11 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type CurrentUser = {
export interface payload {
name: string;
email: string;
shortBio: string;
shortBio?: string;
image?: string;
}

Expand All @@ -28,16 +28,7 @@ export const settingsSchema = z.object({
message: "Name must be at most 50 characters.",
}),
email: z.string().email(),
shortBio: z
.string({
required_error: "Please type a short bio.",
})
.max(150, {
message: "Short bio must be at most 150 characters.",
})
.min(10, {
message: "Short bio must be at least 10 characters.",
}),
shortBio: z.string().optional(),
});

export type SettingsValues = z.infer<typeof settingsSchema>;