public inbox for [email protected]
 help / color / mirror / Atom feed
From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v1 04/10] fix(profile): make social fields default to empty string
Date: Sat,  8 Mar 2025 02:26:14 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Previously, is optional but doesn't have default value for it. This
commit adds default value for social fields to empty string to prevent
null value.

Signed-off-by: Muhammad Rizki <[email protected]>
---
 src/lib/schemas/profile-schema.ts             |  8 ++--
 .../(protected)/settings/profile/+page.svelte | 38 ++++++++-----------
 2 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/src/lib/schemas/profile-schema.ts b/src/lib/schemas/profile-schema.ts
index c4c7228..a9981f1 100644
--- a/src/lib/schemas/profile-schema.ts
+++ b/src/lib/schemas/profile-schema.ts
@@ -13,10 +13,10 @@ export const profileSchema = z.object({
   ext_email: z.string().email("Invalid email format"),
   gender: z.enum(["m", "f"]),
   socials: z.object({
-    github_username: z.string().optional(),
-    telegram_username: z.string().optional(),
-    twitter_username: z.string().optional(),
-    discord_username: z.string().optional()
+    github_username: z.string().optional().default(""),
+    telegram_username: z.string().optional().default(""),
+    twitter_username: z.string().optional().default(""),
+    discord_username: z.string().optional().default("")
   }),
   password: z.string()
 });
diff --git a/src/routes/(protected)/settings/profile/+page.svelte b/src/routes/(protected)/settings/profile/+page.svelte
index 5ddac3b..2e9b76f 100644
--- a/src/routes/(protected)/settings/profile/+page.svelte
+++ b/src/routes/(protected)/settings/profile/+page.svelte
@@ -41,18 +41,10 @@
       formData.append("ext_email", form.data.ext_email);
       formData.append("gender", form.data.gender);
       formData.append("password", form.data.password);
-      if (form.data.socials.github_username) {
-        formData.append("socials[github_username]", form.data.socials.github_username);
-      }
-      if (form.data.socials.telegram_username) {
-        formData.append("socials[telegram_username]", form.data.socials.telegram_username);
-      }
-      if (form.data.socials.twitter_username) {
-        formData.append("socials[twitter_username]", form.data.socials.twitter_username);
-      }
-      if (form.data.socials.discord_username) {
-        formData.append("socials[discord_username]", form.data.socials.discord_username);
-      }
+      formData.append("socials[github_username]", form.data.socials.github_username);
+      formData.append("socials[telegram_username]", form.data.socials.telegram_username);
+      formData.append("socials[twitter_username]", form.data.socials.twitter_username);
+      formData.append("socials[discord_username]", form.data.socials.discord_username);
 
       const {
         data: { res },
@@ -434,17 +426,18 @@
           disabled={$submitting || !isSubmittable || isError}
           {...props}
         >
-          Update profile {isSubmittable}
+          Update profile
         </Button>
       {/snippet}
     </Dialog.Trigger>
 
     <Dialog.Content class="sm:max-w-[425px]">
-      <Dialog.Header>
-        <Dialog.Title>Update Profile Confirmation</Dialog.Title>
-        <Dialog.Description>Confirm changes to your profile here.</Dialog.Description>
-      </Dialog.Header>
-      <div>
+      <form use:enhance enctype="multipart/form-data">
+        <Dialog.Header>
+          <Dialog.Title>Update Profile Confirmation</Dialog.Title>
+          <Dialog.Description>Confirm changes to your profile here.</Dialog.Description>
+        </Dialog.Header>
+
         <Form.Field {form} name="password" class="w-full">
           <Form.Control>
             {#snippet children({ props })}
@@ -463,10 +456,11 @@
             {/snippet}
           </Form.Control>
         </Form.Field>
-      </div>
-      <Dialog.Footer>
-        <Button type="submit" onclick={handleSubmit}>Confirm</Button>
-      </Dialog.Footer>
+
+        <Dialog.Footer>
+          <Button type="submit" onclick={handleSubmit}>Confirm</Button>
+        </Dialog.Footer>
+      </form>
     </Dialog.Content>
   </form>
 </Dialog.Root>
-- 
Muhammad Rizki


  parent reply	other threads:[~2025-03-07 19:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07 19:26 [PATCH v1 00/10] Relative Path, Delete Avatar, Sidebar, Toast Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 01/10] fix(svelte): use relative false Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 02/10] fix(avatar): change avatarImg state to use from auth.user.photo state Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 03/10] chore(profile): add toUpperCase() on getShortName() Muhammad Rizki
2025-03-07 19:26 ` Muhammad Rizki [this message]
2025-03-07 19:26 ` [PATCH v1 05/10] chore(toaster): change toast message position and use richColors Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 06/10] chore(profile): reset password value on success Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 07/10] fix(profile-avatar): add delete avatar method Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 08/10] chore(profile): add space for password confirmation form Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 09/10] feat(ui): add dropdown-menu and update bits-ui version Muhammad Rizki
2025-03-07 19:26 ` [PATCH v1 10/10] chore(sidebar-menu): change sidebar menu look Muhammad Rizki
2025-03-08 15:18 ` [PATCH v1 00/10] Relative Path, Delete Avatar, Sidebar, Toast Ammar Faizi
2025-03-08 15:21   ` Muhammad Rizki
2025-03-08 15:28     ` Ammar Faizi
2025-03-08 15:46       ` Muhammad Rizki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox