Skip to content

Commit

Permalink
fix invitation edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugues Poncet committed Mar 24, 2024
1 parent 01f055b commit a779941
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion admin/src/data/Api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ export async function deleteInvitation(id) {
return api.deleteInvitation(id);
}
export async function updateInvitation(invitation) {
return api.deleteInvitation(invitation);
return api.updateInvitation(invitation);
}
export async function acceptInvitation(acceptedBy, invitCode) {
return api.deleteInvitation(acceptedBy, invitCode);
Expand Down
90 changes: 45 additions & 45 deletions admin/src/page/Invitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,12 @@ class Invitation extends React.Component {
this.updateUrlRedirection = this.updateUrlRedirection.bind(this);
}

openModal(id, invitation) {
if (invitation) {
this.setState({
invForm: {
_id: invitation._id,
code: invitation.invitCode || this.generateInvitationCode(),
email: invitation.email || "",
expireOn: invitation.expireOn || "",
maxUses: invitation.maxUses || "",
libraries: invitation.libraries.map((l) => l.uuid),
downloadPermitted: !!invitation.downloadPermitted,
},
});
}

this.setState({
[`${id}Open`]: true,
});
}

closeModal(id) {
this.setState({
[`${id}Open`]: false,
});
}

componentDidMount() {
this.getPlexLibraries();
this.getInvitations();
this.getUrlRedirection();
}

getInvitationExpireOnDate(expireOn) {
switch (expireOn) {
case "expire1Day":
return new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
case "expire1Week":
return new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000);
case "expire1Month":
return new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000);
case "expire6Months":
return new Date(new Date().getTime() + 6 * 30 * 24 * 60 * 60 * 1000);
case "expire1Year":
return new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
case "expireNever":
return null;
default:
return null;
}
}

async getPlexLibraries() {
const libraries = await Api.getPlexLibraries();

Expand Down Expand Up @@ -180,6 +135,32 @@ class Invitation extends React.Component {
}
}

openModal(id, invitation) {
if (invitation) {
this.setState({
invForm: {
_id: invitation._id,
code: invitation.invitCode || this.generateInvitationCode(),
email: invitation.email || "",
expireOn: invitation.expireOn || "",
maxUses: invitation.maxUses || "",
libraries: invitation.libraries.map((l) => l.uuid),
downloadPermitted: !!invitation.downloadPermitted,
},
});
}

this.setState({
[`${id}Open`]: true,
});
}

closeModal(id) {
this.setState({
[`${id}Open`]: false,
});
}

generateInvitationCode() {
let code = "";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Expand All @@ -193,6 +174,25 @@ class Invitation extends React.Component {
return code;
}

getInvitationExpireOnDate(expireOn) {
switch (expireOn) {
case "expire1Day":
return new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
case "expire1Week":
return new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000);
case "expire1Month":
return new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000);
case "expire6Months":
return new Date(new Date().getTime() + 6 * 30 * 24 * 60 * 60 * 1000);
case "expire1Year":
return new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
case "expireNever":
return null;
default:
return null;
}
}

inputChange(field, value) {
this.setState((state) => ({
invForm: { ...state.invForm, [field]: value },
Expand Down
2 changes: 1 addition & 1 deletion api/routes/invitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ adminInvitationRouter.post("/", async (req, res) => {
libraries: invitation.libraries,
downloadPermitted: invitation.downloadPermitted,
},
{ new: true }
{ useFindAndModify: false, new: true }
);

res.status(200).json(await formatInvitation(updatedInvitation));
Expand Down

0 comments on commit a779941

Please sign in to comment.