Skip to content

Commit 2fd8a9a

Browse files
committed
chore: adjust translation for better language
1 parent 96c597f commit 2fd8a9a

5 files changed

Lines changed: 130 additions & 38 deletions

File tree

src/domains/Profile.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export type ProfileResType = z.infer<typeof profileResSchema>;
2222

2323
export const createProfileFormSchema = (t: (key: string) => string) =>
2424
z.object({
25-
username: z.string().min(1, t("Profile.validation.username-required")),
26-
fullname: z.string().min(1, t("Profile.validation.fullname-required")),
27-
date_of_birth: z.string().min(1, t("Profile.validation.date-of-birth-required")),
28-
gender: z.enum(["Male", "Female"], { required_error: t("Profile.validation.gender-required") }),
29-
phone_number: z.string().min(1, t("Profile.validation.phone-number-required")),
30-
address: z.string().min(1, t("Profile.validation.address-required")),
31-
github: z.string().url(t("Profile.validation.github-invalid-url")).optional().or(z.literal("")),
32-
linkedin: z.string().url(t("Profile.validation.linkedin-invalid-url")).optional().or(z.literal("")),
33-
personal_web: z.string().url(t("Profile.validation.personal-web-invalid-url")).optional().or(z.literal("")),
25+
username: z.string().min(1, t("validation.username-required")),
26+
fullname: z.string().min(1, t("validation.fullname-required")),
27+
date_of_birth: z.string().min(1, t("validation.date-of-birth-required")),
28+
gender: z.string().min(1, t("validation.gender-required")),
29+
phone_number: z.string().min(1, t("validation.phone-number-required")),
30+
address: z.string().min(1, t("validation.address-required")),
31+
github: z.string().url(t("validation.github-invalid-url")).optional().or(z.literal("")),
32+
linkedin: z.string().url(t("validation.linkedin-invalid-url")).optional().or(z.literal("")),
33+
personal_web: z.string().url(t("validation.personal-web-invalid-url")).optional().or(z.literal("")),
3434
});
3535

3636
export type ProfileFormType = z.infer<ReturnType<typeof createProfileFormSchema>>;

src/features/profile/components/ProfileForm.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface ProfileFormProps {
2121
}
2222

2323
const ProfileForm = ({ activeTab }: ProfileFormProps) => {
24-
const t = useTranslations();
24+
const t = useTranslations("Profile");
2525
const profileFormSchema = createProfileFormSchema(t);
2626
const { data, isLoading } = useGetProfile();
2727
const { mutate } = useUpdateProfile();
@@ -33,6 +33,7 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
3333
fullname: "",
3434
date_of_birth: "",
3535
phone_number: "",
36+
gender: "",
3637
address: "",
3738
github: "",
3839
linkedin: "",
@@ -47,6 +48,7 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
4748
fullname: data.fullname || "",
4849
date_of_birth: data.date_of_birth || "",
4950
phone_number: data.phone_number || "",
51+
gender: data.gender || "",
5052
address: data.address || "",
5153
github: data.github || "",
5254
linkedin: data.linkedin || "",
@@ -56,8 +58,6 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
5658
}, [data]);
5759

5860
const onSubmit = (data: ProfileFormType) => {
59-
// ! TODO handle query mutation
60-
console.log("Profile data:", data);
6161
mutate(data);
6262
};
6363

@@ -74,9 +74,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
7474
name="username"
7575
render={({ field }) => (
7676
<FormItem>
77-
<FormLabel>Username</FormLabel>
77+
<FormLabel>{t("form.label.username")}</FormLabel>
7878
<FormControl>
79-
<Input placeholder="Enter your username" {...field} />
79+
<Input placeholder={t("form.placeholder.username")} {...field} />
8080
</FormControl>
8181
<FormMessage />
8282
</FormItem>
@@ -88,9 +88,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
8888
name="fullname"
8989
render={({ field }) => (
9090
<FormItem>
91-
<FormLabel>Full Name</FormLabel>
91+
<FormLabel>{t("form.label.fullname")}</FormLabel>
9292
<FormControl>
93-
<Input placeholder="Enter your full name" {...field} />
93+
<Input placeholder={t("form.placeholder.fullname")} {...field} />
9494
</FormControl>
9595
<FormMessage />
9696
</FormItem>
@@ -102,15 +102,19 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
102102
name="date_of_birth"
103103
render={({ field }) => (
104104
<FormItem className="flex flex-col">
105-
<FormLabel>Date of Birth</FormLabel>
105+
<FormLabel>{t("form.label.date-of-birth")}</FormLabel>
106106
<Popover>
107107
<PopoverTrigger asChild>
108108
<FormControl>
109109
<Button
110110
variant="outline"
111111
className={cn("w-full pl-3 text-left font-normal", !field.value && "text-muted-foreground")}
112112
>
113-
{field.value ? format(new Date(field.value), "PPP") : <span>Pick a date</span>}
113+
{field.value ? (
114+
format(new Date(field.value), "PPP")
115+
) : (
116+
<span>{t("form.placeholder.date-of-birth")}</span>
117+
)}
114118
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
115119
</Button>
116120
</FormControl>
@@ -139,15 +143,15 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
139143
name="gender"
140144
render={({ field }) => (
141145
<FormItem>
142-
<FormLabel>Gender</FormLabel>
146+
<FormLabel>{t("form.label.gender")}</FormLabel>
143147
<FormControl>
144-
<Select onValueChange={field.onChange} defaultValue={field.value}>
148+
<Select onValueChange={field.onChange} value={field.value}>
145149
<SelectTrigger>
146-
<SelectValue placeholder="Select gender" />
150+
<SelectValue placeholder={t("form.placeholder.gender")} />
147151
</SelectTrigger>
148152
<SelectContent>
149-
<SelectItem value="Male">Male</SelectItem>
150-
<SelectItem value="Female">Female</SelectItem>
153+
<SelectItem value="Male">{t("gender.male")}</SelectItem>
154+
<SelectItem value="Female">{t("gender.female")}</SelectItem>
151155
</SelectContent>
152156
</Select>
153157
</FormControl>
@@ -161,9 +165,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
161165
name="phone_number"
162166
render={({ field }) => (
163167
<FormItem>
164-
<FormLabel>Phone Number</FormLabel>
168+
<FormLabel>{t("form.label.phone-number")}</FormLabel>
165169
<FormControl>
166-
<Input placeholder="Enter your phone number" {...field} />
170+
<Input placeholder={t("form.placeholder.phone-number")} {...field} />
167171
</FormControl>
168172
<FormMessage />
169173
</FormItem>
@@ -175,9 +179,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
175179
name="address"
176180
render={({ field }) => (
177181
<FormItem>
178-
<FormLabel>Address</FormLabel>
182+
<FormLabel>{t("form.label.address")}</FormLabel>
179183
<FormControl>
180-
<Input placeholder="Enter your address" {...field} />
184+
<Input placeholder={t("form.placeholder.address")} {...field} />
181185
</FormControl>
182186
<FormMessage />
183187
</FormItem>
@@ -194,9 +198,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
194198
name="github"
195199
render={({ field }) => (
196200
<FormItem>
197-
<FormLabel>GitHub</FormLabel>
201+
<FormLabel>{t("form.label.github")}</FormLabel>
198202
<FormControl>
199-
<Input placeholder="Enter your github account" {...field} />
203+
<Input placeholder={t("form.placeholder.github")} {...field} />
200204
</FormControl>
201205
<FormMessage />
202206
</FormItem>
@@ -208,9 +212,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
208212
name="linkedin"
209213
render={({ field }) => (
210214
<FormItem>
211-
<FormLabel>LinkedIn</FormLabel>
215+
<FormLabel>{t("form.label.linkedin")}</FormLabel>
212216
<FormControl>
213-
<Input placeholder="Enter your linkedin account" {...field} />
217+
<Input placeholder={t("form.placeholder.linkedin")} {...field} />
214218
</FormControl>
215219
<FormMessage />
216220
</FormItem>
@@ -222,9 +226,9 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
222226
name="personal_web"
223227
render={({ field }) => (
224228
<FormItem>
225-
<FormLabel>Personal Website</FormLabel>
229+
<FormLabel>{t("form.label.personal-web")}</FormLabel>
226230
<FormControl>
227-
<Input placeholder="Enter your personal website" {...field} />
231+
<Input placeholder={t("form.placeholder.personal-web")} {...field} />
228232
</FormControl>
229233
<FormMessage />
230234
</FormItem>
@@ -239,7 +243,7 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
239243
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
240244
{renderForm()}
241245
<Button type="submit" className="bg-hmc-base-darkblue dark:bg-hmc-base-lightblue w-full text-white sm:w-auto">
242-
Save Profile
246+
{t("form.save-button")}
243247
</Button>
244248
</form>
245249
</Form>
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { ProfileFormType } from "@/domains/Profile";
22
import { profileService } from "@/services/profile";
33
import { useMutation } from "@tanstack/react-query";
4+
import { toast } from "sonner";
5+
import { useTranslations } from "next-intl";
46

5-
const useUpdateProfile = () =>
6-
useMutation({
7+
const useUpdateProfile = () => {
8+
const t = useTranslations("Profile");
9+
10+
return useMutation({
711
mutationKey: ["updateProfile"],
812
mutationFn: async (payload: ProfileFormType) => profileService.updateProfile(payload),
13+
onSuccess: () => {
14+
toast.success(t("toast.update-success"));
15+
},
916
});
17+
};
1018

1119
export default useUpdateProfile;

src/locales/en.json

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
},
236236
"Profile": {
237237
"validation": {
238-
"username-required": "Nama Panggilan wajib diisi",
238+
"username-required": "Username is required",
239239
"fullname-required": "Fullname is required",
240240
"date-of-birth-required": "Date of birth is required",
241241
"gender-required": "Please select a gender",
@@ -244,6 +244,46 @@
244244
"github-invalid-url": "Please enter a valid GitHub URL",
245245
"linkedin-invalid-url": "Please enter a valid LinkedIn URL",
246246
"personal-web-invalid-url": "Please enter a valid personal website URL"
247+
},
248+
"toast": {
249+
"update-success": "Profile updated successfully!"
250+
},
251+
"form": {
252+
"title": {
253+
"account": "Account Information",
254+
"information": "Additional Information"
255+
},
256+
"tab": {
257+
"account": "Account",
258+
"information": "Information"
259+
},
260+
"placeholder": {
261+
"username": "Enter your username",
262+
"fullname": "Enter your full name",
263+
"date-of-birth": "Pick a date",
264+
"gender": "Select gender",
265+
"phone-number": "Enter your phone number",
266+
"address": "Enter your address",
267+
"github": "Enter your GitHub account",
268+
"linkedin": "Enter your LinkedIn account",
269+
"personal-web": "Enter your personal website"
270+
},
271+
"label": {
272+
"username": "Username",
273+
"fullname": "Full Name",
274+
"date-of-birth": "Date of Birth",
275+
"gender": "Gender",
276+
"phone-number": "Phone Number",
277+
"address": "Address",
278+
"github": "GitHub",
279+
"linkedin": "LinkedIn",
280+
"personal-web": "Personal Website"
281+
},
282+
"save-button": "Save Profile"
283+
},
284+
"gender": {
285+
"male": "Male",
286+
"female": "Female"
247287
}
248288
}
249289
}

src/locales/id.json

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
},
236236
"Profile": {
237237
"validation": {
238-
"username-required": "Nama Panggilan wajib diisi",
238+
"username-required": "Nama pengguna wajib diisi",
239239
"fullname-required": "Nama lengkap wajib diisi",
240240
"date-of-birth-required": "Tanggal lahir wajib diisi",
241241
"gender-required": "Silakan pilih jenis kelamin",
@@ -244,6 +244,46 @@
244244
"github-invalid-url": "Silakan masukkan URL GitHub yang valid",
245245
"linkedin-invalid-url": "Silakan masukkan URL LinkedIn yang valid",
246246
"personal-web-invalid-url": "Silakan masukkan URL website pribadi yang valid"
247+
},
248+
"toast": {
249+
"update-success": "Profil berhasil diperbarui!"
250+
},
251+
"form": {
252+
"title": {
253+
"account": "Informasi Akun",
254+
"information": "Informasi Tambahan"
255+
},
256+
"tab": {
257+
"account": "Akun",
258+
"information": "Informasi"
259+
},
260+
"placeholder": {
261+
"username": "Masukkan nama pengguna",
262+
"fullname": "Masukkan nama lengkap",
263+
"date-of-birth": "Pilih tanggal",
264+
"gender": "Pilih jenis kelamin",
265+
"phone-number": "Masukkan nomor telepon",
266+
"address": "Masukkan alamat",
267+
"github": "Masukkan akun GitHub",
268+
"linkedin": "Masukkan akun LinkedIn",
269+
"personal-web": "Masukkan website pribadi"
270+
},
271+
"label": {
272+
"username": "Nama Pengguna",
273+
"fullname": "Nama Lengkap",
274+
"date-of-birth": "Tanggal Lahir",
275+
"gender": "Jenis Kelamin",
276+
"phone-number": "Nomor Telepon",
277+
"address": "Alamat",
278+
"github": "GitHub",
279+
"linkedin": "LinkedIn",
280+
"personal-web": "Website Pribadi"
281+
},
282+
"save-button": "Simpan Profil"
283+
},
284+
"gender": {
285+
"male": "Laki-laki",
286+
"female": "Perempuan"
247287
}
248288
}
249289
}

0 commit comments

Comments
 (0)