Openstatus www.openstatus.dev
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix: issue with cmd + s on status-page/new form (#916)

* Fix: issue with cmd + save

* Refactor: Moving isUnique check inside of transition

authored by

Priyank Rajai and committed by
GitHub
e8c51181 726db2f7

+27 -29
+27 -29
apps/web/src/components/forms/status-page/form.tsx
··· 117 117 const onSubmit = async ({ ...props }: InsertPage) => { 118 118 startTransition(async () => { 119 119 try { 120 - if (defaultValues) { 121 - await api.page.update.mutate(props); 120 + const isUnique = await checkUniqueSlug(); 121 + if (!isUnique) { 122 + // the user will already have the "error" message - we include a toast as well 123 + toastAction("unique-slug"); 122 124 } else { 123 - const page = await api.page.create.mutate(props); 124 - const id = page?.id || null; 125 - router.replace(`?${updateSearchParams({ id })}`); // to stay on same page and enable 'Advanced' tab 126 - } 125 + if (defaultValues) { 126 + await api.page.update.mutate(props); 127 + } else { 128 + const page = await api.page.create.mutate(props); 129 + const id = page?.id || null; 130 + router.replace(`?${updateSearchParams({ id })}`); // to stay on same page and enable 'Advanced' tab 131 + } 127 132 128 - toast.success("Saved successfully.", { 129 - description: "Your status page is ready to go.", 130 - action: { 131 - label: "Visit", 132 - onClick: () => 133 - window.open(`https://${props.slug}.openstatus.dev`, "_blank") 134 - ?.location, 135 - }, 136 - }); 137 - // otherwise, the form will stay dirty - keepValues is used to keep the current values in the form 138 - form.reset({}, { keepValues: true }); 139 - if (nextUrl) { 140 - router.push(nextUrl); 133 + toast.success("Saved successfully.", { 134 + description: "Your status page is ready to go.", 135 + action: { 136 + label: "Visit", 137 + onClick: () => 138 + window.open(`https://${props.slug}.openstatus.dev`, "_blank") 139 + ?.location, 140 + }, 141 + }); 142 + // otherwise, the form will stay dirty - keepValues is used to keep the current values in the form 143 + form.reset({}, { keepValues: true }); 144 + if (nextUrl) { 145 + router.push(nextUrl); 146 + } 147 + router.refresh(); 141 148 } 142 - router.refresh(); 143 149 } catch { 144 150 toastAction("error"); 145 151 } ··· 159 165 <form 160 166 onSubmit={async (e) => { 161 167 e.preventDefault(); 162 - const isUnique = await checkUniqueSlug(); 163 - if (!isUnique) { 164 - // the user will already have the "error" message - we include a toast as well 165 - toastAction("unique-slug"); 166 - } else { 167 - if (onSubmit) { 168 - void form.handleSubmit(onSubmit)(e); 169 - } 170 - } 168 + void form.handleSubmit(onSubmit)(e); 171 169 }} 172 170 className="grid w-full gap-6" 173 171 >