Skip to content

Commit

Permalink
Merge pull request #366 from kpi-ua/fix-componentDidMount
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy authored Feb 7, 2025
2 parents dc452f6 + 787b3f6 commit f14075c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 39 deletions.
6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class App extends Component {
};
}

async componentDidMount() {
this.setState({ user: await campus.getCurrentUser(true) });
componentDidMount() {
campus.getCurrentUser(true).then(user => {
this.setState({ user });
});
}

render() {
Expand Down
14 changes: 1 addition & 13 deletions src/components/Bb/BbList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,7 @@ class BbList extends React.Component {
};
}

async componentDidMount() {
const response = await campus.getBulletinBoardForCurrentUser(
1,
this.state.pageSize,
);

if (!!response) {
this.setState({
items: response.data,
activePage: 1,
paging: response.paging,
});
}
componentDidMount() {
}

dateToString = (date) =>
Expand Down
19 changes: 12 additions & 7 deletions src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ class Home extends React.Component {
user: null,
};

async componentDidMount() {
componentDidMount() {
this.initializeUser();
}

initializeUser = async () => {
const user = await campus.getCurrentUser();

if (!user) {
this.props.history.push('/login');
return;
} else {
if (!user.modules) {
await campus.logout();
window.location.href = 'https://ecampus.kpi.ua/';
}
}

if (!user.modules) {
await campus.logout();
window.location.href = 'https://ecampus.kpi.ua/';
return;
}

this.setState({ user });
}
};

redirectToOldUI = async (e) => {
e.preventDefault();
Expand Down
8 changes: 6 additions & 2 deletions src/components/KPIID.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class KpiId extends React.Component {
super(props);
}

componentDidMount = async () => {
componentDidMount() {
this.handleAuthentication();
}

handleAuthentication = async () => {
try {
const params = new URLSearchParams(this.props.location.search);
const ticketId = params.get('ticketId');
Expand All @@ -24,7 +28,7 @@ class KpiId extends React.Component {

const currentUser = await campus.exchangeKpiIdTicket(ticketId);

if (!!currentUser) {
if (currentUser) {
this.setState({ redirect: '/home' });
} else {
this.setState({ error: 'Failed to authenticate using KPI ID' });
Expand Down
8 changes: 6 additions & 2 deletions src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ class Login extends React.Component {
redirect: null
};

componentDidMount = async () => {
componentDidMount() {
this.authenticateUser();
}

authenticateUser = async () => {
try {
const currentUser = await campus.getCurrentUser(true);

if (!!currentUser) {
if (currentUser) {
this.setState({ redirect: '/home' });
} else {
this.setState({ error: 'Failed to authenticate using KPI ID' });
Expand Down
8 changes: 6 additions & 2 deletions src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class Settings extends React.Component {
user: {},
};

async componentDidMount() {
componentDidMount() {
this.loadUser();
}

loadUser = async () => {
const user = await campus.getCurrentUser(true);

if (!user) {
Expand All @@ -18,7 +22,7 @@ class Settings extends React.Component {
}

this.setState({ user });
}
};

render() {
const { user } = this.state;
Expand Down
26 changes: 16 additions & 10 deletions src/components/SettingsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ class SettingsEditor extends React.Component {
redirect: null
};

async componentDidMount() {
componentDidMount() {
this.loadUser();
}

loadUser = async () => {
const user = await campus.getCurrentUser();

if (!user) {
this.props.history.push('/login');
return;
}

this.setState({ user });
this.setState({ email: user.email });
this.setState({ credo: user.credo });
this.setState({ scientificInterests: user.scientificInterests });
this.setState({ fullName: user.fullName });
this.setState({ currentPassword: '' });
this.setState({ password: '' });
this.setState({ passwordConfirmation: '' });
}
this.setState({
user,
email: user.email,
credo: user.credo,
scientificInterests: user.scientificInterests,
fullName: user.fullName,
currentPassword: '',
password: '',
passwordConfirmation: '',
});
};

/**
* Validate password
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserProfileImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UserProfileImage extends React.Component {
rnd: 0,
};

async componentDidMount() {
componentDidMount() {
this.setState({ rnd: getRandomNumber() });
}

Expand Down

0 comments on commit f14075c

Please sign in to comment.