Skip to content

Commit

Permalink
Merge pull request #83 from edx/aakbar/PROD-2132
Browse files Browse the repository at this point in the history
Add ability to expire Entitlements
  • Loading branch information
Ali-D-Akbar authored Feb 1, 2021
2 parents f40697d + 2fe77b5 commit f77a4fc
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 161 deletions.
2 changes: 1 addition & 1 deletion src/users/UserPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UserMessagesContext from '../user-messages/UserMessagesContext';
import { isEmail, isValidUsername } from '../utils/index';
import { getAllUserData } from './data/api';
import Enrollments from './Enrollments';
import Entitlements from './Entitlements';
import Entitlements from './entitlements/Entitlements';
import UserSearch from './UserSearch';
import UserSummary from './UserSummary';

Expand Down
37 changes: 4 additions & 33 deletions src/users/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,11 @@ export async function getCourseData(courseUUID) {
}

export async function patchEntitlement({
uuid,
action,
unenrolledRun = null,
comments = null,
uuid, requestData,
}) {
try {
const { data } = await getAuthenticatedHttpClient().patch(
`${getConfig().LMS_BASE_URL}/api/entitlements/v1/entitlements/${uuid}/`,
{
expired_at: null,
support_details: [
{
unenrolled_run: unenrolledRun,
action,
comments,
},
],
},
`${getConfig().LMS_BASE_URL}/api/entitlements/v1/entitlements/${uuid}/`, requestData,
);
return data;
} catch (error) {
Expand All @@ -265,27 +252,11 @@ export async function patchEntitlement({
}

export async function postEntitlement({
user,
courseUuid,
mode,
action,
comments = null,
requestData,
}) {
try {
const { data } = await getAuthenticatedHttpClient().post(
`${getConfig().LMS_BASE_URL}/api/entitlements/v1/entitlements/`,
{
course_uuid: courseUuid,
user,
mode,
refund_locked: true,
support_details: [
{
action,
comments,
},
],
},
`${getConfig().LMS_BASE_URL}/api/entitlements/v1/entitlements/`, requestData,
);
return data;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import {
} from '@edx/paragon';
import classNames from 'classnames';

import UserMessagesContext from '../user-messages/UserMessagesContext';
import AlertList from '../user-messages/AlertList';
import { postEntitlement, patchEntitlement } from './data/api';
import UserMessagesContext from '../../user-messages/UserMessagesContext';
import AlertList from '../../user-messages/AlertList';
import { postEntitlement } from '../data/api';
import { CREATE } from './EntitlementActions';
import { EntitlementPropTypes, EntitlementDefaultProps } from './PropTypes';

export const REISSUE = 'reissue';
export const CREATE = 'create';

export default function EntitlementForm({
formType,
export default function CreateEntitlementForm({
entitlement,
changeHandler,
closeHandler,
Expand All @@ -27,50 +25,36 @@ export default function EntitlementForm({

const submit = useCallback(() => {
clear('entitlements');
if (formType === CREATE) {
postEntitlement({
postEntitlement({
requestData: {
course_uuid: courseUuid,
user,
courseUuid,
mode,
action: CREATE,
comments,
}).then((result) => {
if (result.errors !== undefined) {
result.errors.forEach(error => add(error));
} else {
changeHandler();
}
});
} else if (formType === REISSUE) {
patchEntitlement({
uuid: entitlement.uuid,
action: REISSUE,
unenrolledRun: entitlement.enrollmentCourseRun,
comments,
}).then((result) => {
if (result.errors !== undefined) {
result.errors.forEach(error => add(error));
} else {
changeHandler();
}
});
}
refund_locked: true,
support_details: [{
action: CREATE,
comments,
}],
},
}).then((result) => {
if (result.errors !== undefined) {
result.errors.forEach(error => add(error));
} else {
changeHandler();
}
});
});

const isReissue = formType === REISSUE;
const title = isReissue ? 'Re-issue Entitlement' : 'Create Entitlement';

return (
<section className="card mb-3">
<form className="card-body">
<AlertList topic="entitlements" className="mb-3" />
<h4 className="card-title">{title}</h4>
<h4 className="card-title">Create Entitlement</h4>
<h5 className="card-subtitle">All fields are required</h5>
<div className="form-group">
<label htmlFor="courseUuid">Course UUID</label>
<Input
type="text"
disabled={isReissue}
id="courseUuid"
name="courseUuid"
value={courseUuid}
Expand All @@ -81,7 +65,6 @@ export default function EntitlementForm({
<label htmlFor="mode">Mode</label>
<Input
type="select"
disabled={isReissue}
id="mode"
name="mode"
defaultValue={mode}
Expand Down Expand Up @@ -128,42 +111,15 @@ export default function EntitlementForm({
);
}

EntitlementForm.propTypes = {
formType: PropTypes.string.isRequired,
entitlement: PropTypes.shape({
uuid: PropTypes.string.isRequired,
courseUuid: PropTypes.string.isRequired,
enrollmentCourseRun: PropTypes.string,
created: PropTypes.string.isRequired,
modified: PropTypes.string.isRequired,
expiredAt: PropTypes.string,
mode: PropTypes.string.isRequired,
orderNumber: PropTypes.string,
supportDetails: PropTypes.arrayOf(PropTypes.shape({
supportUser: PropTypes.string,
action: PropTypes.string,
comments: PropTypes.string,
unenrolledRun: PropTypes.string,
})),
user: PropTypes.string.isRequired,
}),
CreateEntitlementForm.propTypes = {
entitlement: EntitlementPropTypes,
user: PropTypes.string.isRequired,
changeHandler: PropTypes.func.isRequired,
closeHandler: PropTypes.func.isRequired,
forwardedRef: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
};

EntitlementForm.defaultProps = {
entitlement: {
uuid: '',
courseUuid: '',
created: '',
modified: '',
expiredAt: '',
mode: 'verified',
orderNumber: '',
supportDetails: [],
user: '',
},
CreateEntitlementForm.defaultProps = {
entitlement: EntitlementDefaultProps,
forwardedRef: null,
};
3 changes: 3 additions & 0 deletions src/users/entitlements/EntitlementActions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const REISSUE = 'reissue';
export const EXPIRE = 'expire';
export const CREATE = 'create';
65 changes: 65 additions & 0 deletions src/users/entitlements/EntitlementForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';
import PropTypes from 'prop-types';
import { CREATE, REISSUE, EXPIRE } from './EntitlementActions';
import CreateEntitlementForm from './CreateEntitlementForm';
import ReissueEntitlementForm from './ReissueEntitlementForm';
import ExpireEntitlementForm from './ExpireEntitlementForm';
import { EntitlementPropTypes, EntitlementDefaultProps } from './PropTypes';

export default function EntitlementForm({
formType,
entitlement,
changeHandler,
closeHandler,
user,
forwardedRef,
}) {
if (formType === CREATE) {
return (
<CreateEntitlementForm
key="entitlement-create-form"
user={user}
entitlement={entitlement}
changeHandler={changeHandler}
closeHandler={closeHandler}
forwardedRef={forwardedRef}
/>
);
} if (formType === EXPIRE) {
return (
<ExpireEntitlementForm
key="entitlement-expire-form"
user={user}
entitlement={entitlement}
changeHandler={changeHandler}
closeHandler={closeHandler}
forwardedRef={forwardedRef}
/>
);
} if (formType === REISSUE) {
return (
<ReissueEntitlementForm
key="entitlement-reissue-form"
user={user}
entitlement={entitlement}
changeHandler={changeHandler}
closeHandler={closeHandler}
forwardedRef={forwardedRef}
/>
);
}
}

EntitlementForm.propTypes = {
formType: PropTypes.string.isRequired,
entitlement: EntitlementPropTypes,
user: PropTypes.string.isRequired,
changeHandler: PropTypes.func.isRequired,
closeHandler: PropTypes.func.isRequired,
forwardedRef: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
};

EntitlementForm.defaultProps = {
entitlement: EntitlementDefaultProps,
forwardedRef: null,
};
Loading

0 comments on commit f77a4fc

Please sign in to comment.