|
| 1 | +import { ReactNode, useState } from "react"; |
| 2 | +import { Link } from "react-router-dom"; |
| 3 | +import { Notification } from "@canonical/react-components"; |
| 4 | + |
| 5 | +import RegisterSnapForm from "./RegisterSnapForm"; |
| 6 | + |
| 7 | +import { filterAvailableStores } from "../../utils"; |
| 8 | + |
| 9 | +import { useBrandStores } from "../../hooks"; |
| 10 | + |
| 11 | +import type { RegistrationResponse } from "./local-types"; |
| 12 | + |
| 13 | +function RegisterSnap(): ReactNode { |
| 14 | + const [isSending, setIsSending] = useState<boolean>(false); |
| 15 | + const [registrationResponse, setRegistrationResponse] = |
| 16 | + useState<RegistrationResponse>(); |
| 17 | + const { data, isLoading } = useBrandStores(); |
| 18 | + |
| 19 | + const availableStores = filterAvailableStores(data || []); |
| 20 | + |
| 21 | + return ( |
| 22 | + <div className="u-fixed-width"> |
| 23 | + {registrationResponse?.error_code === "already_registered" || |
| 24 | + registrationResponse?.error_code === "already_claimed" ? ( |
| 25 | + <> |
| 26 | + <h1 className="p-heading--2"> |
| 27 | + <strong>{registrationResponse.snap_name}</strong> is already taken |
| 28 | + </h1> |
| 29 | + |
| 30 | + <Notification severity="caution"> |
| 31 | + Another publisher already registered{" "} |
| 32 | + <strong>{registrationResponse.snap_name}</strong>. You can{" "} |
| 33 | + <Link |
| 34 | + to={`/register-name-dispute?snap-name=${registrationResponse.snap_name}&store=${registrationResponse.store}`} |
| 35 | + > |
| 36 | + file a dispute |
| 37 | + </Link>{" "} |
| 38 | + to request a transfer of ownership or register a new name below. |
| 39 | + </Notification> |
| 40 | + </> |
| 41 | + ) : ( |
| 42 | + <h1 className="p-heading--2">Register snap</h1> |
| 43 | + )} |
| 44 | + |
| 45 | + {registrationResponse?.error_code === "name-review-required" && ( |
| 46 | + <Notification severity="positive"> |
| 47 | + <strong>{registrationResponse?.snap_name}</strong> has been submitted |
| 48 | + for review |
| 49 | + </Notification> |
| 50 | + )} |
| 51 | + |
| 52 | + {registrationResponse?.error_code === "already_owned" && ( |
| 53 | + <Notification severity="caution"> |
| 54 | + You already own ' |
| 55 | + <Link to={`/${registrationResponse.snap_name}/listing`}> |
| 56 | + <strong>{registrationResponse.snap_name}</strong> |
| 57 | + </Link> |
| 58 | + '. |
| 59 | + </Notification> |
| 60 | + )} |
| 61 | + |
| 62 | + {registrationResponse?.error_code === "reserved_name" && ( |
| 63 | + <Notification severity="caution"> |
| 64 | + '<strong>{registrationResponse.snap_name}</strong>' is reserved. You |
| 65 | + can{" "} |
| 66 | + <a |
| 67 | + href={`/request-reserved-name?snap_name=${registrationResponse.snap_name}&store=${registrationResponse.store}&is_private=${registrationResponse.is_private}`} |
| 68 | + > |
| 69 | + request a reserved name |
| 70 | + </a>{" "} |
| 71 | + or register a new name below. |
| 72 | + </Notification> |
| 73 | + )} |
| 74 | + |
| 75 | + {registrationResponse?.error_code === "no-permission" && ( |
| 76 | + <Notification severity="caution"> |
| 77 | + You do not have permission to register snaps to this store. Contact |
| 78 | + the store administrator. |
| 79 | + </Notification> |
| 80 | + )} |
| 81 | + |
| 82 | + {registrationResponse?.error_code !== "already_registered" && ( |
| 83 | + <p> |
| 84 | + Before you can push your snap to the store, its name must be |
| 85 | + registered |
| 86 | + </p> |
| 87 | + )} |
| 88 | + |
| 89 | + <Notification severity="information"> |
| 90 | + Snap name registrations are subject to manual review. You will be able |
| 91 | + to upload your snap and update its metadata, but you will not be able to |
| 92 | + make the Snap public until the review has been completed. We aim to |
| 93 | + review all registrations within 30 days |
| 94 | + </Notification> |
| 95 | + |
| 96 | + {!isLoading && availableStores.length > 0 && ( |
| 97 | + <RegisterSnapForm |
| 98 | + isSending={isSending} |
| 99 | + setIsSending={setIsSending} |
| 100 | + setRegistrationResponse={setRegistrationResponse} |
| 101 | + availableStores={availableStores} |
| 102 | + /> |
| 103 | + )} |
| 104 | + </div> |
| 105 | + ); |
| 106 | +} |
| 107 | + |
| 108 | +export default RegisterSnap; |
0 commit comments