Skip to content

Commit

Permalink
Merge pull request #28 from RicardoGEsteves/settings-page-improvements
Browse files Browse the repository at this point in the history
feat: ✨ feat(settings-page-improvements): Enhance UI components on settings page
  • Loading branch information
RicardoGEsteves authored Jan 15, 2024
2 parents a936aae + 77e4828 commit 65e40d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
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 />;
}

0 comments on commit 65e40d0

Please sign in to comment.