How to use react-components - 10 common examples

To help you get started, we’ve selected a few react-components examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProtonMail / react-components / models / subscriptionModel.js View on Github external
export const useSubscription = () => {
    const [user] = useUser();
    const api = useApi();

    return useCachedAsyncResult(
        SubscriptionModel.key,
        () => {
            if (user.isPaid) {
                return SubscriptionModel.get(api);
            }
            return Promise.resolve(FREE_SUBSCRIPTION);
        },
        []
    ); // Don't need to depend on the user changes since the subscription is updated through the event manager
};
github ProtonMail / proton-contacts / src / app / components / import / ImportCsvModalContent.js View on Github external
const ImportCsvModalContent = ({ file, onSetVcardContacts }) => {
    const { createNotification } = useNotifications();

    const [isParsingFile, withParsing] = useLoading(true);
    const [contactIndex, setContactIndex] = useState(0);
    const [preVcardsContacts, setPreVcardsContacts] = useState([]);

    const handleClickPrevious = () => setContactIndex((index) => index - 1);
    const handleClickNext = () => setContactIndex((index) => index + 1);

    const handleToggle = (groupIndex) => (index) => {
        if (preVcardsContacts[0][groupIndex][index].combineInto === 'fn-main') {
            // do not allow to uncheck first name and last name simultaneously
            const preVcards = preVcardsContacts[0][groupIndex];
            const firstNameIndex = preVcards.findIndex(({ header }) => header.toLowerCase() === 'first name');
            const lastNameIndex = preVcards.findIndex(({ header }) => header.toLowerCase() === 'last name');
            const isFirstNameChecked = firstNameIndex !== -1 && preVcards[firstNameIndex].checked;
            const isLastNameChecked = lastNameIndex !== -1 && preVcards[lastNameIndex].checked;

            if ((!isFirstNameChecked && index === lastNameIndex) || (!isLastNameChecked && index === firstNameIndex)) {
github ProtonMail / proton-contacts / src / app / components / merge / MergingModalContent.js View on Github external
const MergingModalContent = ({
    contactID,
    userKeysList,
    alreadyMerged,
    beMergedModel = {},
    beDeletedModel = {},
    totalBeMerged = 0,
    onFinish,
    history,
    location
}) => {
    const api = useApi();
    const { privateKeys, publicKeys } = useMemo(() => splitKeys(userKeysList), []);

    const [loading, withLoading] = useLoading(true);
    const [model, setModel] = useState({
        mergedAndEncrypted: [],
        failedOnMergeAndEncrypt: [],
        submitted: [],
        failedOnSubmit: []
    });

    useEffect(() => {
        // Prepare api for allowing cancellation in the middle of the merge
        const abortController = new AbortController();
        const apiWithAbort = (config) => api({ ...config, signal: abortController.signal });

        /**
         * Get a contact from its ID and decrypt it. Return contact as a list of properties
         */
        const getDecryptedContact = async (ID, { signal }) => {
github ProtonMail / react-components / containers / sessions / SessionsSection.js View on Github external
const SessionsSection = () => {
    const { createNotification } = useNotifications();
    const api = useApi();
    const authentication = useAuthentication();
    const [loading, withLoading] = useLoading();
    const [table, setTable] = useState({ sessions: [], total: 0 });
    const { page, list, onNext, onPrevious, onSelect } = usePagination(table.sessions);
    const { createModal } = useModals();

    const fetchSessions = async () => {
        const { Sessions } = await api(querySessions());
        setTable({ sessions: Sessions.reverse(), total: Sessions.length }); // Most recent, first
    };

    const handleRevoke = async (UID) => {
        await api(UID ? revokeSession(UID) : revokeOtherSessions());
        await fetchSessions();
        createNotification({ text: UID ? c('Success').t`Session revoked` : c('Success').t`Sessions revoked` });
    };
github ProtonMail / react-components / containers / payments / subscription / NewSubscriptionModal.js View on Github external
cycle = DEFAULT_CYCLE,
    currency = DEFAULT_CURRENCY,
    coupon,
    planIDs = {},
    onClose,
    ...rest
}) => {
    const TITLE = {
        [SUBSCRIPTION_STEPS.NETWORK_ERROR]: c('Title').t`Network error`,
        [SUBSCRIPTION_STEPS.CUSTOMIZATION]: c('Title').t`Plan customization`,
        [SUBSCRIPTION_STEPS.PAYMENT]: c('Title').t`Checkout`,
        [SUBSCRIPTION_STEPS.UPGRADE]: <div>{c('Title').t`Processing...`}</div>,
        [SUBSCRIPTION_STEPS.THANKS]: <div>{c('Title').t`Thank you!`}</div>
    };

    const api = useApi();
    const [user] = useUser();
    const { call } = useEventManager();
    const { createModal } = useModals();
    const { createNotification } = useNotifications();
    const [vpnCountries, loadingVpnCountries] = useVPNCountries();
    const [plans, loadingPlans] = usePlans();
    const [organization, loadingOrganization] = useOrganization();
    const [loading, withLoading] = useLoading();
    const [loadingCheck, withLoadingCheck] = useLoading();
    const [checkResult, setCheckResult] = useState({});
    const { Credit = 0 } = checkResult;
    const { Code: couponCode } = checkResult.Coupon || {}; // Coupon can be null
    const creditsRemaining = (user.Credit + Credit) / 100;
    const [model, setModel] = useState({
        cycle,
        currency,
github ProtonMail / react-components / containers / account / NewsCheckboxes.js View on Github external
const NewsCheckboxes = () => {
    const [{ News } = {}] = useUserSettings();
    const { createNotification } = useNotifications();
    const { call } = useEventManager();
    const api = useApi();
    const [loading, withLoading] = useLoading();

    const update = async (mask) => {
        await api(updateNews(toggleBit(News, mask)));
        await call();
        createNotification({ text: c('Info').t`Emailing preference updated` });
    };

    const handleChange = (mask) => () => withLoading(update(mask));

    const checkboxes = [
        { id: 'announcements', flag: ANNOUNCEMENTS, text: c('Label for news').t`Major announcements (2-3 per year)` },
        { id: 'features', flag: FEATURES, text: c('Label for news').t`Major features (3-4 per year)` },
        { id: 'business', flag: BUSINESS, text: c('Label for news').t`Proton Business (4-5 per year)` },
        { id: 'newsletter', flag: NEWSLETTER, text: c('Label for news').t`Proton newsletter (5-6 per year)` },
        { id: 'beta', flag: BETA, text: c('Label for news').t`Proton Beta (10-12 per year)` }
github ProtonMail / react-components / models / organizationModel.js View on Github external
export const useOrganization = () => {
    const [user] = useUser();
    const api = useApi();

    return useCachedAsyncResult(
        OrganizationModel.key,
        () => {
            if (user.isPaid) {
                return OrganizationModel.get(api);
            }
            return Promise.resolve(FREE_ORGANIZATION);
        },
        []
    );
};
github ProtonMail / proton-contacts / src / app / hooks / useContact.js View on Github external
const useContact = (contactID) => {
    const cache = useContext(ContactProviderContext);
    const api = useApi();

    const miss = useCallback(() => {
        return api(getContact(contactID)).then(({ Contact }) => Contact);
    }, []);

    return useCachedModelResult(cache, contactID, miss);
};
github ProtonMail / react-components / containers / general / AutoSaveContactsToggle.js View on Github external
const AutoSaveContactsToggle = ({ autoSaveContacts, ...rest }) =&gt; {
    const api = useApi();
    const [loading, withLoading] = useLoading();
    const { createNotification } = useNotifications();
    const { call } = useEventManager();

    const handleChange = async ({ target }) =&gt; {
        await api(updateAutoSaveContacts(+target.checked));
        await call();
        createNotification({ text: c('Success').t`Preference saved` });
    };

    return (
         withLoading(handleChange(event))}
            {...rest}
github ProtonMail / react-components / containers / notification / DailyNotificationsToggle.js View on Github external
const DailyNotificationsToggle = ({ id }) =&gt; {
    const { call } = useEventManager();
    const api = useApi();
    const [{ Email }] = useUserSettings();
    const [loading, withLoading] = useLoading();

    const handleChange = async (checked) =&gt; {
        await api(updateNotifyEmail(checked));
        await call();
    };

    return (
         withLoading(handleChange(+checked))}
        /&gt;
    );

react-components

React components used by Khan Academy

MIT
Latest version published 7 years ago

Package Health Score

48 / 100
Full package analysis