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", () => {
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()
const usernameField = formPage.root.find(elem => elem.props.id === "new_username")
const usernameField = formPage.root.find(elem => elem.props.id === "username")
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()
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()
const emailField = formPage.root.find(elem => elem.props.id === "new_email")
const emailField = formPage.root.find(elem => elem.props.id === "email")
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()
const districtField = formPage.root.find(elem => elem.props.id === "new_district")
const districtField = formPage.root.find(elem => elem.props.id === "district")
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()
// Set value
......
......@@ -18,38 +18,38 @@ const EditProfileForm = () => {
const imageSize = 0.15 * global.vh;
const [form, setField] = useFormState({
new_name: { type: 'text' },
new_username: { type: 'any' },
new_password: { type: 'password' },
confirm_new_password: { type: 'password' },
new_email: { type: 'email' },
new_phone_number: { type: 'phone' },
new_district: { type: 'any' },
new_sub_district: { type: 'any' },
name: { type: 'text' },
username: { type: 'any' },
password: { type: 'password' },
confirm_password: { type: 'password' },
email: { type: 'email' },
phone_number: { type: 'phone' },
district: { type: 'any' },
sub_district: { type: 'any' },
});
const [serverHasError, setServerHasError] = useState(false);
const [messageErrors, setMessageErrors] = useState({
new_name: '',
new_username: '',
new_password: '',
confirm_new_password: '',
new_email: '',
new_phone_number: '',
new_district: '',
new_sub_district: '',
name: '',
username: '',
password: '',
confirm_password: '',
email: '',
phone_number: '',
district: '',
sub_district: '',
})
const [modalVisible, setModalVisible] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const initFieldValue = () => {
setField('new_name', global.user.name);
setField('new_username', global.user.username);
setField('new_email', global.user.email);
setField('new_phone_number', global.user.phone_number);
setField('new_district', global.user.district);
setField('new_sub_district', global.user.sub_district);
setField('name', global.user.name);
setField('username', global.user.username);
setField('email', global.user.email);
setField('phone_number', global.user.phone_number);
setField('district', global.user.district);
setField('sub_district', global.user.sub_district);
}
useEffect(initFieldValue, []);
......@@ -102,103 +102,103 @@ const EditProfileForm = () => {
</Modal>
<InputField>
<Field
id="new_name"
id="name"
name="Nama"
placeholder="Nama Lengkap Anda"
isRequired={true}
information={messageErrors.new_name}
value={form.fields.new_name.value}
updateValue={val => setField('new_name', val)}
information={messageErrors.name}
value={form.fields.name.value}
updateValue={val => setField('name', val)}
/>
</InputField>
<InputField>
<Field
id="new_username"
id="username"
name="Username"
placeholder="Username Anda"
isRequired={true}
information={messageErrors.new_username}
value={form.fields.new_username.value}
updateValue={val => setField('new_username', val)}
information={messageErrors.username}
value={form.fields.username.value}
updateValue={val => setField('username', val)}
/>
</InputField>
<InputField>
<Field
id="new_password"
id="password"
name="Password"
placeholder="Password Anda"
isRequired={true}
shouldSecure={true}
information={messageErrors.new_password}
value={form.fields.new_password.value}
updateValue={val => setField('new_password', val)}
information={messageErrors.password}
value={form.fields.password.value}
updateValue={val => setField('password', val)}
/>
</InputField>
<InputField>
<Field
id="confirm_new_password"
id="confirm_password"
name="Konfirmasi Password"
placeholder="Konfirmasi Password Anda"
isRequired={true}
shouldSecure={true}
information={messageErrors.confirm_new_password}
value={form.fields.confirm_new_password.value}
updateValue={val => setField('confirm_new_password', val)}
information={messageErrors.confirm_password}
value={form.fields.confirm_password.value}
updateValue={val => setField('confirm_password', val)}
/>
</InputField>
<InputField>
<Field
id="new_email"
id="email"
name="Email"
placeholder="Email Anda"
isRequired={true}
information={messageErrors.new_email}
value={form.fields.new_email.value}
updateValue={val => setField('new_email', val)}
information={messageErrors.email}
value={form.fields.email.value}
updateValue={val => setField('email', val)}
/>
</InputField>
<InputField>
<Field
id="new_phone_number"
id="phone_number"
name="Nomor Handphone"
placeholder="No HP Anda"
isRequired={true}
information={messageErrors.new_phone_number}
value={form.fields.new_phone_number.value}
updateValue={val => setField('new_phone_number', val)}
information={messageErrors.phone_number}
value={form.fields.phone_number.value}
updateValue={val => setField('phone_number', val)}
/>
</InputField>
<InputField>
<Field
id="new_district"
id="district"
type={3}
name="Kecamatan"
placeholder="Pilih Kecamatan"
isRequired={true}
information={messageErrors.new_district}
value={form.fields.new_district.value || KECAMATAN_VALUES[0].value}
updateValue={val => setField('new_district', val)}
information={messageErrors.district}
value={form.fields.district.value || KECAMATAN_VALUES[0].value}
updateValue={val => setField('district', val)}
values={KECAMATAN_VALUES}
/>
</InputField>
<InputField>
<Field
id="new_sub_district"
id="sub_district"
type={3}
name="Kelurahan"
placeholder="Pilih Kelurahan"
isRequired={true}
information={messageErrors.new_sub_district}
value={form.fields.new_sub_district.value || KELURAHAN_VALUES[KECAMATAN_VALUES[0].value][0].value}
updateValue={val => setField('new_sub_district', val)}
values={(form.fields.new_district.value) ? KELURAHAN_VALUES[form.fields.new_district.value] : KELURAHAN_VALUES[KECAMATAN_VALUES[0].value]}
information={messageErrors.sub_district}
value={form.fields.sub_district.value || KELURAHAN_VALUES[KECAMATAN_VALUES[0].value][0].value}
updateValue={val => setField('sub_district', val)}
values={(form.fields.district.value) ? KELURAHAN_VALUES[form.fields.district.value] : KELURAHAN_VALUES[KECAMATAN_VALUES[0].value]}
/>
</InputField>
<Button
......@@ -208,14 +208,14 @@ const EditProfileForm = () => {
setIsLoading(true)
const response = await global.services.main.editProfile({
new_name: form.fields.new_name.value,
new_username: form.fields.new_username.value.replace(/\s+$/, ''),
new_password: form.fields.new_password.value,
confirm_new_password: form.fields.confirm_new_password.value,
new_email: form.fields.new_email.value,
new_phone_number: form.fields.new_phone_number.value,
new_district: form.fields.new_district.value,
new_sub_district: form.fields.new_sub_district.value
name: form.fields.name.value,
username: form.fields.username.value.replace(/\s+$/, ''),
password: form.fields.password.value,
confirm_password: form.fields.confirm_password.value,
email: form.fields.email.value,
phone_number: form.fields.phone_number.value,
district: form.fields.district.value,
sub_district: form.fields.sub_district.value
})
if (response.status === 200) {
......@@ -232,27 +232,27 @@ const EditProfileForm = () => {
});
} else if (response.status === 400) {
const errors = {
new_name: response.data.new_name || [],
new_username: response.data.new_username || [],
new_password: response.data.new_password || [],
confirm_new_password: response.data.confirm_new_password || [],
new_email: response.data.new_email || [],
new_phone_number: response.data.new_phone_number || [],
new_district: response.data.new_district || [],
new_sub_district: response.data.new_sub_district || [],
name: response.data.name || [],
username: response.data.username || [],
password: response.data.password || [],
confirm_password: response.data.confirm_password || [],
email: response.data.email || [],
phone_number: response.data.phone_number || [],
district: response.data.district || [],
sub_district: response.data.sub_district || [],
}
if (response.data.non_field_errors) {
switch (response.data.non_field_errors[0]) {
case "Inconsistent password and confirmation":
errors.confirm_new_password = [
...errors.confirm_new_password,
errors.confirm_password = [
...errors.confirm_password,
"Password dan konfirmasinya tidak konsisten"
]
break;
case "Inconsistent district and sub district value":
errors.new_district = [
...errors.new_district,
errors.district = [
...errors.district,
"Kecamatan dan kelurahan tidak konsisten"
]
break;
......@@ -262,14 +262,14 @@ const EditProfileForm = () => {
}
setMessageErrors({
new_name: translateError(errors.new_name[0] || ""),
new_username: translateError(errors.new_username[0] || "") + " Username hanya boleh terdiri dari karakter alfanumerik atau salah satu dari {@, +, ., _, -}",
new_password: translateError(errors.new_password[0] || ""),
confirm_new_password: translateError(errors.confirm_new_password[0] || ""),
new_email: translateError(errors.new_email[0] || ""),
new_phone_number: translateError(errors.new_phone_number[0] || ""),
new_district: translateError(errors.new_district[0] || ""),
new_sub_district: translateError(errors.new_sub_district[0] || ""),
name: translateError(errors.name[0] || ""),
username: translateError(errors.username[0] || ""),
password: translateError(errors.password[0] || ""),
confirm_password: translateError(errors.confirm_password[0] || ""),
email: translateError(errors.email[0] || ""),
phone_number: translateError(errors.phone_number[0] || ""),
district: translateError(errors.district[0] || ""),
sub_district: translateError(errors.sub_district[0] || ""),
})
} else if (response.status === 500) {
if (response.data.includes("IntegrityError")) {
......
......@@ -80,14 +80,14 @@ describe('Test API that needs token', () => {
test('Edit current user profile', async () => {
const newUserProfile = {
"new_username": "admin",
"new_name": "admin",
"new_email": "admin@email.com",
"new_password": "akupasskamu123",
"confirm_new_password": "akupasskamu123",
"new_phone_number": "0812682163256",
"new_district": "Tapos",
"new_sub_district": "Sukatani",
"username": "admin",
"name": "admin",
"email": "admin@email.com",
"password": "akupasskamu123",
"confirm_password": "akupasskamu123",
"phone_number": "0812682163256",
"district": "Tapos",
"sub_district": "Sukatani",
}
mockedAxios.request.mockImplementationOnce(
......
......@@ -95,14 +95,14 @@ export default function useMainService(token: string) {
}
interface EditProfileFormType {
new_name: string;
new_username: string;
new_password: string;
confirm_new_password: string;
new_email: string;
new_phone_number: string;
new_district: string;
new_sub_district: string;
name: string;
username: string;
password: string;
confirm_password: string;
email: string;
phone_number: string;
district: string;
sub_district: string;
}
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