Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 15 additions & 25 deletions resources/js/Pages/CreateInst.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export default function CreateInst() {
// TODO: switch to error instead of setting result_area
const [error, setError] = useState(null);

// Any update to this schemas list needs to be reflected in the handleSubmit() function call as a checkbox.
const schemas = [
{ name: 'Custom', selected: false },
{ name: 'PDP', selected: false },
{ name: 'Edvise', selected: false },
{ name: 'Legacy', selected: false },
Expand Down Expand Up @@ -84,30 +82,17 @@ export default function CreateInst() {
'Error: Institution name is required.';
return;
}
// Enforce the selection of at least one schema type.
const edvise = event.target.elements.Edvise?.checked ?? false;
const legacy = event.target.elements.Legacy?.checked ?? false;
if (
!event.target.elements.Custom.checked &&
!event.target.elements.PDP.checked &&
!edvise &&
!legacy
) {
document.getElementById('result_area').innerHTML =
'Error: Schema type must contain at least one selection.';
return;
}
// At most one of PDP, Edvise, or Legacy (API allows only one school type).
const schoolTypeCount = [event.target.elements.PDP.checked, edvise, legacy].filter(Boolean).length;
if (schoolTypeCount > 1) {
const pdpChecked = event.target.elements.PDP.checked;
const schoolTypeCount = [pdpChecked, edvise, legacy].filter(Boolean).length;
if (schoolTypeCount !== 1) {
document.getElementById('result_area').innerHTML =
'Error: Select at most one of PDP, Edvise, or Legacy.';
schoolTypeCount === 0
? 'Error: Select exactly one of PDP, Edvise, or Legacy.'
: 'Error: Select at most one of PDP, Edvise, or Legacy.';
return;
}
// We currently only have custom for potential other schemas. Note that the schema passed to the API call must match the corresponding backend schema enum value.
let other_schemas = event.target.elements.Custom.checked
? ['UNKNOWN']
: null;
var emailDict = {};
var accessDict = {};
Array.from(event.target.elements).forEach(input => {
Expand All @@ -130,11 +115,16 @@ export default function CreateInst() {
const payload = {
name: event.target.elements.inst_name.value,
state: event.target.elements.state.value,
allowed_schemas: other_schemas,
allowed_emails:
constructedEmailDict.length == 0 ? null : constructedEmailDict,
Object.keys(constructedEmailDict).length === 0
? null
: constructedEmailDict,
is_pdp: pdp,
pdp_id: event.target.elements.pdp_id?.value || null,
// Only send PDP id when PDP is selected; leftover text would otherwise
// combine with Edvise/Legacy and trip API mutual-exclusivity checks.
pdp_id: pdpChecked
? (event.target.elements.pdp_id?.value || null)
: null,
};
if (edvise) payload.is_edvise = true;
if (legacy) payload.is_legacy = true;
Expand Down Expand Up @@ -270,7 +260,7 @@ export default function CreateInst() {
<div className="flex flex-col w-1/2">
<fieldset>
<legend className="text-base font-semibold text-gray-900">
Schemas accepted by this institution
Institution type
</legend>
<div className="mt-4 divide-y divide-gray-200 border-b border-t border-gray-200">
{schemas.map((schem, idx) => (
Expand Down
4 changes: 1 addition & 3 deletions resources/js/Pages/EditInst.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function EditInst() {
const [error, setError] = useState(null);
const [addUserCounter, setAddUserCounter] = useState(1);
const [schemas] = useState([
{ name: 'Custom', selected: false },
{ name: 'PDP', selected: false },
{ name: 'Edvise', selected: false },
{ name: 'Legacy', selected: false },
Expand Down Expand Up @@ -135,7 +134,6 @@ export default function EditInst() {
const payload = {
name: formData.get('inst_name'),
state: formData.get('state'),
allowed_schemas: formData.get('Custom') ? ['UNKNOWN'] : null,
allowed_emails: constructEmailDict(formData),
is_pdp: pdp,
pdp_id: pdp ? (formData.get('pdp_id') || null) : null,
Expand Down Expand Up @@ -216,7 +214,7 @@ export default function EditInst() {
<div className="flex flex-col w-1/2">
<fieldset>
<legend className="text-base font-semibold text-gray-900">
Schemas accepted by this institution
Institution type
</legend>
<div className="mt-4 divide-y divide-gray-200 border-b border-t border-gray-200">
{schemas.map((schem, idx) => (
Expand Down