diff --git a/assets/js/EditProfile.jsx b/assets/js/EditProfile.jsx index dadbd4d274315932a0fc49427a82ac6a26182389..525deebc19cda8426d2621346ab08bb8c4d54f49 100644 --- a/assets/js/EditProfile.jsx +++ b/assets/js/EditProfile.jsx @@ -11,9 +11,10 @@ import { import Server from './lib/Server'; import Storage from './lib/Storage'; import ModalAlert from './components/ModalAlert'; -import ProfileHandler from './ProfileHandler'; +import Dumper from './lib/Dumper'; +import { isFromGithubLinkValid } from './Utils'; -export default class EditProfile extends ProfileHandler { +export default class EditProfile extends React.Component { static propTypes = { route: PropTypes.object.isRequired, params: PropTypes.object.isRequired, @@ -156,6 +157,72 @@ export default class EditProfile extends ProfileHandler { return dateIndexArray.reverse().join(' '); } + handleSubmit = (e) => { + e.preventDefault(); + if (!isFromGithubLinkValid(this.state.form.github_url)) { + this.modalAlert.open( + 'Pembaharuan profil gagal', + 'Pastikan link github yang anda tulis benar.(Berpola : https://github.com/<username>', + ); + } else { + const submitForm = {}; + Object.keys(this.state.form).forEach((key) => { + if (this.state.form[key] !== '') { + submitForm[key] = this.state.form[key]; + } + }); + this.setState({ loading: true }); + Server.submit( + `/students/${this.state.id}/profile/`, + submitForm, + 'PATCH', + ).then( + () => { + this.setState({ loading: false }); + this.modalAlert.open( + 'Profil berhasil diperbaharui', + 'Silakan periksa kembali profil anda', + this.getProfile, + ); + }, + (error) => error.then((r) => { + this.setState({ loading: false }); + this.modalAlert.open('Pembaharuan profil gagal', Dumper.dump(r)); + }), + ); + } + }; + + handleFile = (e) => { + const { form } = this.state; + form[e.target.name] = e.target.files[0]; + this.setState({ form }); + }; + + handleChange = (e) => { + const { form } = this.state; + form[e.target.name] = e.target.value; + this.setState({ form }); + }; + + handleCheckbox = (e, d) => { + const { form } = this.state; + form[d.name] = d.checked; + this.setState({ form, show_transcript: d.checked }); + }; + + handleRadioGender = (e, { value }) => { + const { form } = this.state; + form.gender = value; + this.setState({ form }); + }; + + handleRadio = (e, { value }) => { + const { form } = this.state; + form.job_seeking_status = value; + this.setState({ form }); + }; + updateForm(show) { if (show) { return ( diff --git a/assets/js/ProfilePage.jsx b/assets/js/ProfilePage.jsx index 53d7799b0b3ce337173a8008d22990f67c1c7f6d..f26fec2873250780fe40abc2129220569164efff 100755 --- a/assets/js/ProfilePage.jsx +++ b/assets/js/ProfilePage.jsx @@ -5,7 +5,6 @@ import { Image, Header, Icon, - Checkbox, Container, Button, Form,