All files / publisher/pages/RegisterSnap RegisterSnap.tsx

100% Statements 6/6
84.61% Branches 11/13
100% Functions 1/1
100% Lines 6/6

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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80                            11x 11x   11x   11x 11x   11x                                                                                                                  
import { useState } from "react";
import { Link } from "react-router-dom";
import { Notification } from "@canonical/react-components";
 
import RegistrationError from "./RegistrationError";
import RegisterSnapForm from "./RegisterSnapForm";
 
import { filterAvailableStores } from "../../utils";
 
import { useBrandStores } from "../../hooks";
 
import type { RegistrationResponse } from "./local-types";
 
function RegisterSnap(): React.JSX.Element {
  const [isSending, setIsSending] = useState<boolean>(false);
  const [registrationResponse, setRegistrationResponse] =
    useState<RegistrationResponse>();
  const { data, isLoading } = useBrandStores();
 
  const availableStores = filterAvailableStores(data || []);
  const [selectedStore, setSelectedStore] = useState<string>("ubuntu");
 
  return (
    <div className="u-fixed-width">
      {registrationResponse?.error_code === "already_registered" ||
      registrationResponse?.error_code === "already_claimed" ? (
        <>
          <h1 className="p-heading--2">
            <strong>{registrationResponse.snap_name}</strong> is already taken
          </h1>
 
          <Notification severity="caution">
            Another publisher already registered{" "}
            <strong>{registrationResponse.snap_name}</strong>. You can{" "}
            <Link
              to={`/register-name-dispute?snap-name=${registrationResponse.snap_name}&store=${registrationResponse.store}`}
            >
              file a dispute
            </Link>{" "}
            to request a transfer of ownership or register a new name below.
          </Notification>
        </>
      ) : (
        <h1 className="p-heading--2">Register snap</h1>
      )}
 
      {registrationResponse?.error_code && (
        <RegistrationError
          snapName={registrationResponse.snap_name}
          isPrivate={registrationResponse.is_private}
          store={registrationResponse.store}
          errorCode={registrationResponse.error_code}
        />
      )}
 
      {selectedStore === "ubuntu" && (
        <Notification severity="information">
          Snap name registrations are subject to manual review. You will be able
          to upload your snap and update its metadata, but you will not be able
          to make the Snap public until the review has been completed. We aim to
          review all registrations within 30 days
        </Notification>
      )}
 
      {!isLoading && availableStores.length > 0 && (
        <RegisterSnapForm
          selectedStore={selectedStore}
          setSelectedStore={setSelectedStore}
          isSending={isSending}
          setIsSending={setIsSending}
          setRegistrationResponse={setRegistrationResponse}
          availableStores={availableStores}
        />
      )}
    </div>
  );
}
 
export default RegisterSnap;