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

feat: ✨ feat(settings-page-improvements): Enhance UI components on settings page #28

Merged
merged 1 commit into from
Jan 15, 2024
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
2 changes: 1 addition & 1 deletion app/(protected)/_components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Navbar = () => {
asChild
variant="secondary"
size="sm"
className="w-full text-background hover:text-sky-400"
className="w-full text-sky-400 hover:text-background"
>
<MdMenu />
</Button>
Expand Down
18 changes: 15 additions & 3 deletions app/(protected)/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useSession } from "next-auth/react";
import { RiUserSettingsLine } from "react-icons/ri";

import { useCurrentUser } from "@/hooks/use-current-user";
import { useIsClient } from "@/hooks/use-is-client";
import Spinner from "@/components/spinner";
import { SettingsSchema } from "@/schemas";
import { settings } from "@/actions/settings";
import { Card, CardHeader, CardContent } from "@/components/ui/card";
Expand Down Expand Up @@ -45,6 +47,8 @@ export default function SettingsPage() {

const [isPending, startTransition] = useTransition();

const isClient = useIsClient();

const form = useForm<z.infer<typeof SettingsSchema>>({
resolver: zodResolver(SettingsSchema),
defaultValues: {
Expand Down Expand Up @@ -75,12 +79,15 @@ export default function SettingsPage() {
} catch (error) {
setError("Something went wrong!");
} finally {
form.reset();
setError("");
setSuccess("");
// TODO: Check if needed
// form.reset();
// setError("");
// setSuccess("");
}
};

if (!isClient) return <Spinner />;

return (
<Card className="w-auto shadow-sm">
<CardHeader className="flex-row items-center justify-center font-semibold gap-x-3">
Expand Down Expand Up @@ -113,6 +120,7 @@ export default function SettingsPage() {
</FormItem>
)}
/>

{user?.isOAuth === false && (
<>
<FormField
Expand Down Expand Up @@ -195,6 +203,7 @@ export default function SettingsPage() {
/>
</>
)}

<FormField
control={form.control}
name="role"
Expand All @@ -220,6 +229,7 @@ export default function SettingsPage() {
</FormItem>
)}
/>

{user?.isOAuth === false && (
<FormField
control={form.control}
Expand All @@ -234,11 +244,13 @@ export default function SettingsPage() {
</div>
<FormControl>
<Switch
value={field.name}
disabled={isPending}
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
Expand Down
3 changes: 2 additions & 1 deletion components/client-only.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useIsClient } from "@/hooks/use-is-client";
import Spinner from "./spinner";

export function ClientOnly({ children }: { children: React.ReactNode }) {
const isClient = useIsClient();

return isClient ? <>{children}</> : null;
return isClient ? <>{children}</> : <Spinner />;
}
Loading