Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update group-settings.tsx

Steven Tey4048e807ec17
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/group-settings.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/group-settings.tsx
index 20649542e6..30bcffa932 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/group-settings.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/group-settings.tsx
@@ -3,13 +3,13 @@
import { useApiMutation } from "@/lib/swr/use-api-mutation";
import useGroup from "@/lib/swr/use-group";
import useProgram from "@/lib/swr/use-program";
+import { GroupProps } from "@/lib/types";
import { updateGroupSchema } from "@/lib/zod/schemas/groups";
import { GroupColorPicker } from "@/ui/partners/groups/group-color-picker";
-import { Button } from "@dub/ui";
+import { Button, LoadingSpinner } from "@dub/ui";
import { cn } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
import { useParams, useRouter } from "next/navigation";
-import { useEffect } from "react";
import { Controller, useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";
@@ -17,15 +17,25 @@ import { z } from "zod";
type FormData = z.input<typeof updateGroupSchema>;
export function GroupSettings() {
- const router = useRouter();
- const { program } = useProgram();
- const { groupSlug, slug } = useParams<{ groupSlug: string; slug: string }>();
- const { makeRequest: updateGroup, isSubmitting } = useApiMutation();
+ const { groupSlug } = useParams<{ groupSlug: string }>();
const { group } = useGroup({
groupIdOrSlug: groupSlug,
});
+ if (!group) {
+ return <LoadingSpinner />;
+ }
+
+ return <GroupSettingsForm group={group} />;
+}
+
+function GroupSettingsForm({ group }: { group: GroupProps }) {
+ const router = useRouter();
+ const { program } = useProgram();
+ const { slug } = useParams<{ slug: string }>();
+ const { makeRequest: updateGroup, isSubmitting } = useApiMutation();
+
const {
register,
handleSubmit,
@@ -38,17 +48,6 @@ export function GroupSettings() {
mode: "onBlur",
});
- // Reset form when group data loads
- useEffect(() => {
- if (group) {
- reset({
- name: group.name,
- slug: group.slug,
- color: group.color || "",
- });
- }
- }, [group, reset]);
-
const onSubmit = async (data: FormData) => {
if (!group) {
return;
@@ -104,29 +103,16 @@ export function GroupSettings() {
placeholder="Group name"
/>
<div className="absolute inset-y-0 right-0 flex items-center pr-2.5">
- <div className="relative">
- <div
- className="h-6 w-6 cursor-pointer rounded-full border-none"
- style={{
- backgroundColor: watch("color") || "",
- }}
- onClick={() =>
- document.getElementById("color-picker")?.click()
- }
- />
- <div className="absolute inset-y-0 right-0 flex items-center pr-2.5">
- <Controller
- control={control}
- name="color"
- render={({ field }) => (
- <GroupColorPicker
- color={field.value}
- onChange={field.onChange}
- />
- )}
+ <Controller
+ control={control}
+ name="color"
+ render={({ field }) => (
+ <GroupColorPicker
+ color={field.value}
+ onChange={field.onChange}
/>
- </div>
- </div>
+ )}
+ />
</div>
</div>