Fakultas Ilmu Komputer UI

Commit 31af6eba authored by jahnsmichael's avatar jahnsmichael
Browse files

[REFACTOR] rename for convention with backend

parent e3872471
Pipeline #81806 passed with stage
in 17 minutes and 6 seconds
...@@ -68,28 +68,28 @@ describe("EditProfileForm", () => { ...@@ -68,28 +68,28 @@ describe("EditProfileForm", () => {
expect(formPage).toBeTruthy() expect(formPage).toBeTruthy()
const nameField = formPage.root.find(elem => elem.props.id === "new_name") const nameField = formPage.root.find(elem => elem.props.id === "name")
expect(nameField).toBeTruthy() expect(nameField).toBeTruthy()
const usernameField = formPage.root.find(elem => elem.props.id === "new_username") const usernameField = formPage.root.find(elem => elem.props.id === "username")
expect(usernameField).toBeTruthy() expect(usernameField).toBeTruthy()
const passwordField = formPage.root.find(elem => elem.props.id === "new_password") const passwordField = formPage.root.find(elem => elem.props.id === "password")
expect(passwordField).toBeTruthy() expect(passwordField).toBeTruthy()
const confirmPasswordField = formPage.root.find(elem => elem.props.id === "confirm_new_password") const confirmPasswordField = formPage.root.find(elem => elem.props.id === "confirm_password")
expect(confirmPasswordField).toBeTruthy() expect(confirmPasswordField).toBeTruthy()
const emailField = formPage.root.find(elem => elem.props.id === "new_email") const emailField = formPage.root.find(elem => elem.props.id === "email")
expect(emailField).toBeTruthy() expect(emailField).toBeTruthy()
const phoneField = formPage.root.find(elem => elem.props.id === "new_phone_number") const phoneField = formPage.root.find(elem => elem.props.id === "phone_number")
expect(phoneField).toBeTruthy() expect(phoneField).toBeTruthy()
const districtField = formPage.root.find(elem => elem.props.id === "new_district") const districtField = formPage.root.find(elem => elem.props.id === "district")
expect(districtField).toBeTruthy() expect(districtField).toBeTruthy()
const sub_districtField = formPage.root.find(elem => elem.props.id === "new_sub_district") const sub_districtField = formPage.root.find(elem => elem.props.id === "sub_district")
expect(sub_districtField).toBeTruthy() expect(sub_districtField).toBeTruthy()
// Set value // Set value
......
...@@ -18,38 +18,38 @@ const EditProfileForm = () => { ...@@ -18,38 +18,38 @@ const EditProfileForm = () => {
const imageSize = 0.15 * global.vh; const imageSize = 0.15 * global.vh;
const [form, setField] = useFormState({ const [form, setField] = useFormState({
new_name: { type: 'text' }, name: { type: 'text' },
new_username: { type: 'any' }, username: { type: 'any' },
new_password: { type: 'password' }, password: { type: 'password' },
confirm_new_password: { type: 'password' }, confirm_password: { type: 'password' },
new_email: { type: 'email' }, email: { type: 'email' },
new_phone_number: { type: 'phone' }, phone_number: { type: 'phone' },
new_district: { type: 'any' }, district: { type: 'any' },
new_sub_district: { type: 'any' }, sub_district: { type: 'any' },
}); });
const [serverHasError, setServerHasError] = useState(false); const [serverHasError, setServerHasError] = useState(false);
const [messageErrors, setMessageErrors] = useState({ const [messageErrors, setMessageErrors] = useState({
new_name: '', name: '',
new_username: '', username: '',
new_password: '', password: '',
confirm_new_password: '', confirm_password: '',
new_email: '', email: '',
new_phone_number: '', phone_number: '',
new_district: '', district: '',
new_sub_district: '', sub_district: '',
}) })
const [modalVisible, setModalVisible] = useState(false); const [modalVisible, setModalVisible] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const initFieldValue = () => { const initFieldValue = () => {
setField('new_name', global.user.name); setField('name', global.user.name);
setField('new_username', global.user.username); setField('username', global.user.username);
setField('new_email', global.user.email); setField('email', global.user.email);
setField('new_phone_number', global.user.phone_number); setField('phone_number', global.user.phone_number);
setField('new_district', global.user.district); setField('district', global.user.district);
setField('new_sub_district', global.user.sub_district); setField('sub_district', global.user.sub_district);
} }
useEffect(initFieldValue, []); useEffect(initFieldValue, []);
...@@ -102,103 +102,103 @@ const EditProfileForm = () => { ...@@ -102,103 +102,103 @@ const EditProfileForm = () => {
</Modal> </Modal>
<InputField> <InputField>
<Field <Field
id="new_name" id="name"
name="Nama" name="Nama"
placeholder="Nama Lengkap Anda" placeholder="Nama Lengkap Anda"
isRequired={true} isRequired={true}
information={messageErrors.new_name} information={messageErrors.name}
value={form.fields.new_name.value} value={form.fields.name.value}
updateValue={val => setField('new_name', val)} updateValue={val => setField('name', val)}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="new_username" id="username"
name="Username" name="Username"
placeholder="Username Anda" placeholder="Username Anda"
isRequired={true} isRequired={true}
information={messageErrors.new_username} information={messageErrors.username}
value={form.fields.new_username.value} value={form.fields.username.value}
updateValue={val => setField('new_username', val)} updateValue={val => setField('username', val)}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="new_password" id="password"
name="Password" name="Password"
placeholder="Password Anda" placeholder="Password Anda"
isRequired={true} isRequired={true}
shouldSecure={true} shouldSecure={true}
information={messageErrors.new_password} information={messageErrors.password}
value={form.fields.new_password.value} value={form.fields.password.value}
updateValue={val => setField('new_password', val)} updateValue={val => setField('password', val)}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="confirm_new_password" id="confirm_password"
name="Konfirmasi Password" name="Konfirmasi Password"
placeholder="Konfirmasi Password Anda" placeholder="Konfirmasi Password Anda"
isRequired={true} isRequired={true}
shouldSecure={true} shouldSecure={true}
information={messageErrors.confirm_new_password} information={messageErrors.confirm_password}
value={form.fields.confirm_new_password.value} value={form.fields.confirm_password.value}
updateValue={val => setField('confirm_new_password', val)} updateValue={val => setField('confirm_password', val)}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="new_email" id="email"
name="Email" name="Email"
placeholder="Email Anda" placeholder="Email Anda"
isRequired={true} isRequired={true}
information={messageErrors.new_email} information={messageErrors.email}
value={form.fields.new_email.value} value={form.fields.email.value}
updateValue={val => setField('new_email', val)} updateValue={val => setField('email', val)}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="new_phone_number" id="phone_number"
name="Nomor Handphone" name="Nomor Handphone"
placeholder="No HP Anda" placeholder="No HP Anda"
isRequired={true} isRequired={true}
information={messageErrors.new_phone_number} information={messageErrors.phone_number}
value={form.fields.new_phone_number.value} value={form.fields.phone_number.value}
updateValue={val => setField('new_phone_number', val)} updateValue={val => setField('phone_number', val)}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="new_district" id="district"
type={3} type={3}
name="Kecamatan" name="Kecamatan"
placeholder="Pilih Kecamatan" placeholder="Pilih Kecamatan"
isRequired={true} isRequired={true}
information={messageErrors.new_district} information={messageErrors.district}
value={form.fields.new_district.value || KECAMATAN_VALUES[0].value} value={form.fields.district.value || KECAMATAN_VALUES[0].value}
updateValue={val => setField('new_district', val)} updateValue={val => setField('district', val)}
values={KECAMATAN_VALUES} values={KECAMATAN_VALUES}
/> />
</InputField> </InputField>
<InputField> <InputField>
<Field <Field
id="new_sub_district" id="sub_district"
type={3} type={3}
name="Kelurahan" name="Kelurahan"
placeholder="Pilih Kelurahan" placeholder="Pilih Kelurahan"
isRequired={true} isRequired={true}
information={messageErrors.new_sub_district} information={messageErrors.sub_district}
value={form.fields.new_sub_district.value || KELURAHAN_VALUES[KECAMATAN_VALUES[0].value][0].value} value={form.fields.sub_district.value || KELURAHAN_VALUES[KECAMATAN_VALUES[0].value][0].value}
updateValue={val => setField('new_sub_district', val)} updateValue={val => setField('sub_district', val)}
values={(form.fields.new_district.value) ? KELURAHAN_VALUES[form.fields.new_district.value] : KELURAHAN_VALUES[KECAMATAN_VALUES[0].value]} values={(form.fields.district.value) ? KELURAHAN_VALUES[form.fields.district.value] : KELURAHAN_VALUES[KECAMATAN_VALUES[0].value]}
/> />
</InputField> </InputField>
<Button <Button
...@@ -208,14 +208,14 @@ const EditProfileForm = () => { ...@@ -208,14 +208,14 @@ const EditProfileForm = () => {
setIsLoading(true) setIsLoading(true)
const response = await global.services.main.editProfile({ const response = await global.services.main.editProfile({
new_name: form.fields.new_name.value, name: form.fields.name.value,
new_username: form.fields.new_username.value.replace(/\s+$/, ''), username: form.fields.username.value.replace(/\s+$/, ''),
new_password: form.fields.new_password.value, password: form.fields.password.value,
confirm_new_password: form.fields.confirm_new_password.value, confirm_password: form.fields.confirm_password.value,
new_email: form.fields.new_email.value, email: form.fields.email.value,
new_phone_number: form.fields.new_phone_number.value, phone_number: form.fields.phone_number.value,
new_district: form.fields.new_district.value, district: form.fields.district.value,
new_sub_district: form.fields.new_sub_district.value sub_district: form.fields.sub_district.value
}) })
if (response.status === 200) { if (response.status === 200) {
...@@ -232,27 +232,27 @@ const EditProfileForm = () => { ...@@ -232,27 +232,27 @@ const EditProfileForm = () => {
}); });
} else if (response.status === 400) { } else if (response.status === 400) {
const errors = { const errors = {
new_name: response.data.new_name || [], name: response.data.name || [],
new_username: response.data.new_username || [], username: response.data.username || [],
new_password: response.data.new_password || [], password: response.data.password || [],
confirm_new_password: response.data.confirm_new_password || [], confirm_password: response.data.confirm_password || [],
new_email: response.data.new_email || [], email: response.data.email || [],
new_phone_number: response.data.new_phone_number || [], phone_number: response.data.phone_number || [],
new_district: response.data.new_district || [], district: response.data.district || [],
new_sub_district: response.data.new_sub_district || [], sub_district: response.data.sub_district || [],
} }
if (response.data.non_field_errors) { if (response.data.non_field_errors) {
switch (response.data.non_field_errors[0]) { switch (response.data.non_field_errors[0]) {
case "Inconsistent password and confirmation": case "Inconsistent password and confirmation":
errors.confirm_new_password = [ errors.confirm_password = [
...errors.confirm_new_password, ...errors.confirm_password,
"Password dan konfirmasinya tidak konsisten" "Password dan konfirmasinya tidak konsisten"
] ]
break; break;
case "Inconsistent district and sub district value": case "Inconsistent district and sub district value":
errors.new_district = [ errors.district = [
...errors.new_district, ...errors.district,
"Kecamatan dan kelurahan tidak konsisten" "Kecamatan dan kelurahan tidak konsisten"
] ]
break; break;
...@@ -262,14 +262,14 @@ const EditProfileForm = () => { ...@@ -262,14 +262,14 @@ const EditProfileForm = () => {
} }
setMessageErrors({ setMessageErrors({
new_name: translateError(errors.new_name[0] || ""), name: translateError(errors.name[0] || ""),
new_username: translateError(errors.new_username[0] || "") + " Username hanya boleh terdiri dari karakter alfanumerik atau salah satu dari {@, +, ., _, -}", username: translateError(errors.username[0] || ""),
new_password: translateError(errors.new_password[0] || ""), password: translateError(errors.password[0] || ""),
confirm_new_password: translateError(errors.confirm_new_password[0] || ""), confirm_password: translateError(errors.confirm_password[0] || ""),
new_email: translateError(errors.new_email[0] || ""), email: translateError(errors.email[0] || ""),
new_phone_number: translateError(errors.new_phone_number[0] || ""), phone_number: translateError(errors.phone_number[0] || ""),
new_district: translateError(errors.new_district[0] || ""), district: translateError(errors.district[0] || ""),
new_sub_district: translateError(errors.new_sub_district[0] || ""), sub_district: translateError(errors.sub_district[0] || ""),
}) })
} else if (response.status === 500) { } else if (response.status === 500) {
if (response.data.includes("IntegrityError")) { if (response.data.includes("IntegrityError")) {
......
...@@ -80,14 +80,14 @@ describe('Test API that needs token', () => { ...@@ -80,14 +80,14 @@ describe('Test API that needs token', () => {
test('Edit current user profile', async () => { test('Edit current user profile', async () => {
const newUserProfile = { const newUserProfile = {
"new_username": "admin", "username": "admin",
"new_name": "admin", "name": "admin",
"new_email": "admin@email.com", "email": "admin@email.com",
"new_password": "akupasskamu123", "password": "akupasskamu123",
"confirm_new_password": "akupasskamu123", "confirm_password": "akupasskamu123",
"new_phone_number": "0812682163256", "phone_number": "0812682163256",
"new_district": "Tapos", "district": "Tapos",
"new_sub_district": "Sukatani", "sub_district": "Sukatani",
} }
mockedAxios.request.mockImplementationOnce( mockedAxios.request.mockImplementationOnce(
......
...@@ -95,14 +95,14 @@ export default function useMainService(token: string) { ...@@ -95,14 +95,14 @@ export default function useMainService(token: string) {
} }
interface EditProfileFormType { interface EditProfileFormType {
new_name: string; name: string;
new_username: string; username: string;
new_password: string; password: string;
confirm_new_password: string; confirm_password: string;
new_email: string; email: string;
new_phone_number: string; phone_number: string;
new_district: string; district: string;
new_sub_district: string; sub_district: string;
} }
async function editProfile(body: EditProfileFormType) { async function editProfile(body: EditProfileFormType) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment