Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/actions/admin-access-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const getAdminAccesses =
createAction(RECEIVE_ADMIN_ACCESSES),
`${window.API_BASE_URL}/api/v1/summit-administrator-groups`,
authErrorHandler,
{ order, orderDir, term }
{ order, orderDir, term, page, perPage }
)(params)(dispatch).then(() => {
dispatch(stopLoading());
});
Expand Down Expand Up @@ -129,7 +129,7 @@ export const resetAdminAccessForm = () => (dispatch) => {
};

export const saveAdminAccess =
(entity, noAlert = false) =>
(entity, redirectOnCreate = true) =>
async (dispatch) => {
const accessToken = await getAccessTokenSafely();

Expand All @@ -139,40 +139,42 @@ export const saveAdminAccess =
const params = { access_token: accessToken };

if (entity.id) {
putRequest(
return putRequest(
createAction(UPDATE_ADMIN_ACCESS),
createAction(ADMIN_ACCESS_UPDATED),
`${window.API_BASE_URL}/api/v1/summit-administrator-groups/${entity.id}`,
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then(() => {
if (!noAlert)
dispatch(showSuccessMessage(T.translate("admin_access.saved")));
else dispatch(stopLoading());
dispatch(showSuccessMessage(T.translate("admin_access.saved")));
});
} else {
const successMessage = {
title: T.translate("general.done"),
html: T.translate("admin_access.created"),
type: "success"
};

postRequest(
createAction(UPDATE_ADMIN_ACCESS),
createAction(ADMIN_ACCESS_ADDED),
`${window.API_BASE_URL}/api/v1/summit-administrator-groups`,
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then((payload) => {
}
return postRequest(
createAction(UPDATE_ADMIN_ACCESS),
createAction(ADMIN_ACCESS_ADDED),
`${window.API_BASE_URL}/api/v1/summit-administrator-groups`,
normalizedEntity,
authErrorHandler,
entity
)(params)(dispatch).then((payload) => {
if (redirectOnCreate) {
const successMessage = {
title: T.translate("general.done"),
html: T.translate("admin_access.created"),
type: "success"
};

dispatch(
showMessage(successMessage, () => {
history.push(`/app/admin-access/${payload.response.id}`);
})
);
});
}
return;
}

dispatch(showSuccessMessage(T.translate("admin_access.created")));
});
};

export const deleteAdminAccess = (adminAccessId) => async (dispatch) => {
Expand Down
78 changes: 47 additions & 31 deletions src/components/forms/admin-access-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
* */

import React from "react";
import T from "i18n-react/dist/i18n-react";
import "awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css";
import Input from "openstack-uicore-foundation/lib/components/inputs/text-input"
import MemberInput from "openstack-uicore-foundation/lib/components/inputs/member-input"
import SummitInput from "openstack-uicore-foundation/lib/components/inputs/summit-input";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Grid2 from "@mui/material/Grid2";
import Typography from "@mui/material/Typography";
import {
scrollToError,
hasErrors,
Expand All @@ -37,7 +41,7 @@ class AdminAccessForm extends React.Component {
this.handleSubmit = this.handleSubmit.bind(this);
}

componentDidUpdate(prevProps, prevState, snapshot) {
componentDidUpdate(prevProps) {
const state = {};
scrollToError(this.props.errors);

Expand All @@ -63,7 +67,7 @@ class AdminAccessForm extends React.Component {
errors[id] = "";
entity[id] = value;

this.setState({ entity: entity, errors: errors });
this.setState({ entity, errors });
}

handleSubmit(ev) {
Expand All @@ -77,54 +81,66 @@ class AdminAccessForm extends React.Component {
const { entity, errors } = this.state;

return (
<form className="admin-access-form">
<Box
component="form"
className="admin-access-form"
sx={{ width: "100%" }}
>
<input type="hidden" id="id" value={entity.id} />
<div className="row form-group">
<div className="col-md-4">
<label> {T.translate("admin_access.title")} *</label>
<Grid2 container spacing={2}>
<Grid2 size={12}>
<Typography component="label" sx={{ display: "block", mb: 0.5 }}>
{T.translate("admin_access.title")} *
</Typography>
<Input
id="title"
value={entity.title}
onChange={this.handleChange}
className="form-control"
error={hasErrors("title", errors)}
/>
</div>
<div className="col-md-4">
<label> {T.translate("admin_access.members")} *</label>
</Grid2>
<Grid2 size={{ xs: 12, md: 6 }}>
<Typography component="label" sx={{ display: "block", mb: 0.5 }}>
{T.translate("admin_access.members")} *
</Typography>
<MemberInput
id="members"
value={entity.members}
getOptionLabel={(member) => {
return member.hasOwnProperty("email")
? `${member.first_name} ${member.last_name} (${member.email})`
: `${member.first_name} ${member.last_name} (${member.id})`;
}}
getOptionLabel={(member) =>
`${member.first_name} ${member.last_name} (${
member.hasOwnProperty("email") ? member.email : member.id
})`
}
onChange={this.handleChange}
multi={true}
multi
/>
</div>
<div className="col-md-4">
<label> {T.translate("admin_access.summits")} *</label>
</Grid2>
<Grid2 size={{ xs: 12, md: 6 }}>
<Typography component="label" sx={{ display: "block", mb: 0.5 }}>
{T.translate("admin_access.summits")} *
</Typography>
<SummitInput
id="summits"
value={entity.summits}
onChange={this.handleChange}
multi={true}
multi
/>
</div>
</div>
<div className="row">
<div className="col-md-12 submit-buttons">
<input
</Grid2>
<Grid2
size={12}
sx={{ display: "flex", justifyContent: "flex-end", pt: 1 }}
>
<Button
type="button"
variant="contained"
onClick={this.handleSubmit}
className="btn btn-primary pull-right"
value={T.translate("general.save")}
/>
</div>
</div>
</form>
>
{T.translate("general.save")}
</Button>
</Grid2>
</Grid2>
</Box>
);
}
}
Expand Down
67 changes: 28 additions & 39 deletions src/layouts/admin-access-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,41 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
* */

import React from "react";
import { Switch, Route, Redirect } from "react-router-dom";
import T from "i18n-react/dist/i18n-react";
import { connect } from "react-redux";
import { Breadcrumb } from "react-breadcrumbs";
import Restrict from "../routes/restrict";
import AdminAccessListPage from "../pages/admin_access/admin-access-list-page";
import EditAdminAccessPage from "../pages/admin_access/edit-admin-access-page";

class AdminAccessLayout extends React.Component {
render() {
const { match } = this.props;
const AdminAccessLayout = ({ match }) => (
<div>
<Breadcrumb
data={{
title: T.translate("admin_access.admin_access"),
pathname: match.url
}}
/>

return (
<div>
<Breadcrumb
data={{
title: T.translate("admin_access.admin_access"),
pathname: match.url
}}
/>
<Switch>
<Route strict exact path={match.url} component={AdminAccessListPage} />
<Route
strict
exact
path={`${match.url}/new`}
component={AdminAccessListPage}
/>
<Route
strict
exact
path={`${match.url}/:access_id(\\d+)`}
component={AdminAccessListPage}
/>
<Redirect to={match.url} />
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before the routes would only match on / or digit, or new. Now it matches everything , for example app/admin-access/santi. it is not equivalent to what we had

</Switch>
</div>
);

<Switch>
<Route
exact
strict
path={match.url}
component={AdminAccessListPage}
/>
<Route
strict
exact
path={`${match.url}/new`}
component={EditAdminAccessPage}
/>
<Route
path={`${match.url}/:access_id(\\d+)`}
component={EditAdminAccessPage}
/>
<Redirect to={`/app/admin-access`} />
</Switch>
</div>
);
}
}

export default Restrict(connect(null, {})(AdminAccessLayout), "admin-access");
export default Restrict(AdminAccessLayout, "admin-access");
Loading
Loading