All files / client/src/views/admin/components LoginProviderSelector.tsx

66.66% Statements 8/12
100% Branches 0/0
75% Functions 3/4
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37              356x 98x 57x 57x 57x   171x                                              
import { ChangeEvent, ReactElement, useState } from "react";
import { useTranslation } from "react-i18next";
import { LoginProvider } from "shared/config/eventConfigTypes";
import { Dropdown } from "client/components/Dropdown";
import { useAppDispatch, useAppSelector } from "client/utils/hooks";
import { submitSetLoginProvider } from "client/views/admin/adminThunks";
 
export const LoginProviderSelector = (): ReactElement => {
  const loginProvider = useAppSelector((state) => state.admin.loginProvider);
  const { t } = useTranslation();
  const dispatch = useAppDispatch();
  const [loading, setLoading] = useState<boolean>(false);
 
  const strategies = Object.values(LoginProvider).map((value) => ({
    value,
    title: t(`loginProvider.${value}`),
  }));
 
  return (
    <div>
      <span>{t("admin.loginProvider")}</span>{" "}
      <Dropdown
        options={strategies}
        selectedValue={loginProvider}
        onChange={async (event: ChangeEvent<HTMLSelectElement>) => {
          setLoading(true);
          await dispatch(
            submitSetLoginProvider(event.target.value as LoginProvider),
          );
          setLoading(false);
        }}
        loading={loading}
      />
    </div>
  );
};