* feat: update the layout for organizations * feat: update the layout for an organization * feat: organization logos are square * feat: change the text on the org visit button * feat: initialize the dropdown menu * feat: trigger the modal * feat: update the text in the model * feat: tweak wording * WIP/feat: hook up a route with an action that calls an organization delete worker. * feat: redirect after showing the notice * feat: update the authorization required to be super admin * feat: add the notice to localization * spec: integration test * spec: fix * spec: delete worker * chore: update the link * feat: add safe navigation * feat: make sure that we show an error if the organization has credits * fix: error message for modal unspent credits * feat add the spec for the helper * fix: remove rspec preface * fix: small fixes to tests and I18n * fix: updated the number of orgs * feat: update the message * feat: update the message * chore: remove inclusion of helper * feat: change the name of the parameter * chore: newline
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import { showWindowModal } from '@utilities/showModal';
|
|
|
|
const modalContents = new Map();
|
|
/**
|
|
* Helper function to handle finding and caching modal content. Since our Preact modal helper works by duplicating HTML content,
|
|
* and our user modals rely on IDs to label form controls, we remove the original hidden content from the DOM to avoid ID conflicts.
|
|
*
|
|
* @param {string} modalContentSelector The CSS selector used to identify the correct modal content
|
|
*/
|
|
const getModalContents = (modalContentSelector) => {
|
|
if (!modalContents.has(modalContentSelector)) {
|
|
const modalContentElement = document.querySelector(modalContentSelector);
|
|
const modalContent = modalContentElement.innerHTML;
|
|
|
|
modalContentElement.remove();
|
|
modalContents.set(modalContentSelector, modalContent);
|
|
}
|
|
|
|
return modalContents.get(modalContentSelector);
|
|
};
|
|
|
|
/**
|
|
* Helper function for views which use admin user modals. May be attached as an event listener, and its actions will only be triggered
|
|
* if the target of the event is a recognised user modal trigger.
|
|
*
|
|
* @param {Object} event
|
|
*/
|
|
export const showOrganizationModal = (event) => {
|
|
const { dataset } = event.target;
|
|
|
|
if (!Object.prototype.hasOwnProperty.call(dataset, 'modalContentSelector')) {
|
|
// We're not trying to trigger a modal.
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
const { modalTitle, modalSize, modalContentSelector } = dataset;
|
|
|
|
showWindowModal({
|
|
modalContent: getModalContents(modalContentSelector),
|
|
title: modalTitle,
|
|
size: modalSize,
|
|
});
|
|
};
|