Skip to content

Commit 7bc4ad8

Browse files
chore: small improvements2
1 parent a712813 commit 7bc4ad8

File tree

4 files changed

+50
-28
lines changed

4 files changed

+50
-28
lines changed

src/cohorts/CohortsPage.tsx

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import DisableCohortsModal from './components/DisableCohortsModal';
88
import messages from './messages';
99
import DisabledCohortsView from './components/DisabledCohortsView';
1010
import EnabledCohortsView from './components/EnabledCohortsView';
11-
import { CohortProvider } from './components/CohortContext';
11+
import { CohortProvider, useCohortContext } from './components/CohortContext';
1212

13-
const CohortsPage = () => {
13+
const CohortsPageContent = () => {
1414
const intl = useIntl();
1515
const { courseId = '' } = useParams();
1616
const { data: cohortStatus } = useCohortStatus(courseId);
1717
const { mutate: toggleCohortsMutate } = useToggleCohorts(courseId);
1818
const [isOpenDisableModal, setIsOpenDisableModal] = useState(false);
19+
const { clearSelectedCohort } = useCohortContext();
1920
const { isCohorted = false } = cohortStatus ?? {};
2021

2122
const handleEnableCohorts = () => {
@@ -28,36 +29,44 @@ const CohortsPage = () => {
2829
const handleDisableCohorts = () => {
2930
toggleCohortsMutate({ isCohorted: false },
3031
{
32+
onSuccess: () => clearSelectedCohort(),
3133
onError: (error) => console.log(error)
3234
});
3335
setIsOpenDisableModal(false);
3436
};
3537

3638
return (
37-
<CohortProvider>
38-
<div className="mt-4.5 mb-4 mx-4">
39-
<div className="d-inline-flex align-items-center">
40-
<h3 className="mb-0 text-gray-700">{intl.formatMessage(messages.cohortsTitle)}</h3>
41-
{isCohorted && (
42-
<div className="small">
43-
<IconButton
44-
alt={intl.formatMessage(messages.disableCohorts)}
45-
iconAs={Settings}
46-
iconClassNames="mb-2 text-gray-500"
47-
size="sm"
48-
variant="secondary"
49-
onClick={() => setIsOpenDisableModal(true)}
50-
/>
51-
</div>
52-
)}
53-
</div>
54-
{isCohorted ? (
55-
<EnabledCohortsView />
56-
) : (
57-
<DisabledCohortsView onEnableCohorts={handleEnableCohorts} />
39+
<div className="mt-4.5 mb-4 mx-4">
40+
<div className="d-inline-flex align-items-center">
41+
<h3 className="mb-0 text-gray-700">{intl.formatMessage(messages.cohortsTitle)}</h3>
42+
{isCohorted && (
43+
<div className="small">
44+
<IconButton
45+
alt={intl.formatMessage(messages.disableCohorts)}
46+
iconAs={Settings}
47+
iconClassNames="mb-2 text-gray-500"
48+
size="sm"
49+
variant="secondary"
50+
onClick={() => setIsOpenDisableModal(true)}
51+
/>
52+
</div>
5853
)}
59-
<DisableCohortsModal isOpen={isOpenDisableModal} onClose={() => setIsOpenDisableModal(false)} onConfirmDisable={handleDisableCohorts} />
6054
</div>
55+
{isCohorted ? (
56+
<EnabledCohortsView />
57+
) : (
58+
<DisabledCohortsView onEnableCohorts={handleEnableCohorts} />
59+
)}
60+
<DisableCohortsModal isOpen={isOpenDisableModal} onClose={() => setIsOpenDisableModal(false)} onConfirmDisable={handleDisableCohorts} />
61+
</div>
62+
);
63+
};
64+
65+
// It was necessary to wrap the entire content with CohortProvider here to avoid errors in the use of cohort hooks within a provider
66+
const CohortsPage = () => {
67+
return (
68+
<CohortProvider>
69+
<CohortsPageContent />
6170
</CohortProvider>
6271
);
6372
};

src/cohorts/components/EnabledCohortsView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ const EnabledCohortsView = () => {
6767
return (
6868
<>
6969
<div className="d-flex mt-4.5">
70-
<FormControl placeholder={intl.formatMessage(messages.selectCohortPlaceholder)} name="cohort" as="select" onChange={handleSelectCohort} value={selectedCohort?.id?.toString() ?? 'null'} disabled={displayAddForm}>
70+
<FormControl
71+
as="select"
72+
disabled={displayAddForm || cohortsList.length === 0}
73+
name="cohort"
74+
placeholder={intl.formatMessage(messages.selectCohortPlaceholder)}
75+
value={selectedCohort?.id?.toString() ?? 'null'}
76+
onChange={handleSelectCohort}
77+
>
7178
{
7279
cohortsList.map((cohort) => (
7380
<option key={cohort.id} value={cohort.id}>

src/cohorts/components/ManageLearners.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ const ManageLearners = () => {
2929
<h3 className="text-primary-700">{intl.formatMessage(messages.addLearnersTitle)}</h3>
3030
<p className="x-small mb-2.5">{intl.formatMessage(messages.addLearnersSubtitle)}</p>
3131
<p className="mb-2 text-primary-500">{intl.formatMessage(messages.addLearnersInstructions)}</p>
32-
<FormControl as="textarea" className="mb-2" placeholder={intl.formatMessage(messages.learnersExample)} onChange={(e) => setUsers(e.target.value)} />
32+
<FormControl
33+
as="textarea"
34+
className="mb-2"
35+
rows={4}
36+
placeholder={intl.formatMessage(messages.learnersExample)}
37+
onChange={(e) => setUsers(e.target.value)}
38+
/>
3339
<p className="x-small mb-2.5">{intl.formatMessage(messages.addLearnersFootnote)}</p>
3440
<Button variant="primary" className="mt-2" onClick={handleAddLearners}>+ {intl.formatMessage(messages.addLearnersLabel)}</Button>
3541
</div>

src/cohorts/data/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const createCohort = async (courseId: string, cohortDetails: BasicCohortD
2828
};
2929

3030
export const getContentGroups = async (courseId: string) => {
31-
const url = `${getApiBaseUrl()}/api/instructor/v1/courses/${courseId}/content_groups`;
31+
const url = `${getApiBaseUrl()}/api/instructor/v1/courses/${courseId}/group_configurations`;
3232
const { data } = await getAuthenticatedHttpClient().get(url);
3333
return camelCaseObject(data);
3434
};
@@ -41,7 +41,7 @@ export const patchCohort = async (courseId: string, cohortId: number, cohortDeta
4141
};
4242

4343
export const addLearnersToCohort = async (courseId: string, cohortId: number, users: string[]) => {
44-
const url = `${getApiBaseUrl()}/api/cohorts/v1/courses/${courseId}/cohorts/${cohortId}/users`;
44+
const url = `${getApiBaseUrl()}/api/cohorts/v1/courses/${courseId}/cohorts/${cohortId}/users/`;
4545
const { data } = await getAuthenticatedHttpClient().post(url, { users });
4646
return camelCaseObject(data);
4747
};

0 commit comments

Comments
 (0)