Skip to content

Commit ce8186b

Browse files
committed
chore: Apply application layout to request reserved name page
1 parent c39ccd4 commit ce8186b

5 files changed

Lines changed: 162 additions & 77 deletions

File tree

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { ReactNode, useState } from "react";
2+
import { useRecoilValue } from "recoil";
3+
import {
4+
Form,
5+
Button,
6+
Input,
7+
Textarea,
8+
Row,
9+
Col,
10+
Notification,
11+
Icon,
12+
} from "@canonical/react-components";
13+
14+
import { brandStoresState } from "../../state/brandStoreState";
15+
16+
function RequestReservedName(): ReactNode {
17+
const [claimComment, setClaimComment] = useState<string>();
18+
const [isSubmitting, setIsSubmitting] = useState<boolean>();
19+
const [showSuccessNotification, setShowSuccessNotification] =
20+
useState<boolean>(false);
21+
const [errorNotification, setErrorNotification] = useState<string>();
22+
const stores = useRecoilValue(brandStoresState);
23+
const params = new URLSearchParams(document.location.search);
24+
const snapName = params.get("snap_name");
25+
const store = params.get("store");
26+
27+
const selectedStore = stores.find((s) => s.name === store) || {
28+
name: "Global",
29+
id: "ubuntu",
30+
};
31+
32+
return (
33+
<>
34+
<h1 className="p-heading--2">
35+
Request reserved name <strong>{snapName}</strong>
36+
</h1>
37+
38+
{showSuccessNotification && (
39+
<Notification severity="positive">
40+
Your claim has been submitted and will be reviewed
41+
</Notification>
42+
)}
43+
44+
{errorNotification && (
45+
<Notification severity="caution">{errorNotification}</Notification>
46+
)}
47+
48+
{stores.length === 0 && (
49+
<>
50+
<Icon name="spinner" className="u-animation--spin" />
51+
&nbsp;Loading data...
52+
</>
53+
)}
54+
55+
{stores.length > 0 && (
56+
<Form
57+
onSubmit={async (e) => {
58+
e.preventDefault();
59+
60+
setIsSubmitting(true);
61+
62+
const response = await fetch("/api/register-name-dispute", {
63+
method: "POST",
64+
headers: {
65+
"X-CSRFToken": window.CSRF_TOKEN,
66+
},
67+
body: JSON.stringify({
68+
"snap-name": snapName,
69+
"claim-comment": claimComment,
70+
}),
71+
});
72+
73+
if (!response.ok) {
74+
setIsSubmitting(false);
75+
throw new Error("Unable to request reserved name");
76+
}
77+
78+
const responseData = await response.json();
79+
80+
setTimeout(() => {
81+
if (!responseData.success) {
82+
setErrorNotification(responseData.message);
83+
} else {
84+
setShowSuccessNotification(true);
85+
}
86+
87+
setIsSubmitting(false);
88+
}, 1500);
89+
}}
90+
>
91+
<Row>
92+
<Col size={2}>
93+
<label htmlFor="store">Store</label>
94+
</Col>
95+
<Col size={6}>
96+
<Input
97+
type="text"
98+
readOnly
99+
id="store"
100+
value={selectedStore.name}
101+
/>
102+
</Col>
103+
</Row>
104+
105+
<Row>
106+
<Col size={2}>
107+
<label htmlFor="snap">Snap name</label>
108+
</Col>
109+
<Col size={6}>
110+
<Input type="text" id="snap" readOnly value={snapName || ""} />
111+
</Col>
112+
</Row>
113+
114+
<Row>
115+
<Col size={2}>
116+
<label htmlFor="comment">Comment</label>
117+
</Col>
118+
<Col size={6}>
119+
<Textarea
120+
id="comment"
121+
help="Why you have rights to claim this name"
122+
value={claimComment}
123+
onChange={(e) => {
124+
setClaimComment(e.target.value);
125+
}}
126+
/>
127+
</Col>
128+
</Row>
129+
<hr />
130+
<div className="u-align--right">
131+
<a className="p-button" href="/register-snap">
132+
Register snap
133+
</a>
134+
<Button
135+
type="submit"
136+
appearance="positive"
137+
disabled={!claimComment || isSubmitting}
138+
>
139+
{isSubmitting ? (
140+
<>
141+
<Icon name="spinner" className="u-animation--spin" light />
142+
&nbsp;Requesting
143+
</>
144+
) : (
145+
<>Yes, I am sure</>
146+
)}
147+
</Button>
148+
</div>
149+
</Form>
150+
)}
151+
</>
152+
);
153+
}
154+
155+
export default RequestReservedName;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./RequestReservedName";

static/js/publisher/publisher.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Build from "./pages/Build";
1515
import Releases from "./pages/Releases";
1616
import AccountSnaps from "./pages/AccountSnaps";
1717
import RegisterNameDispute from "./pages/RegisterNameDispute";
18+
import RequestReservedName from "./pages/RequestReservedName";
1819

1920
const router = createBrowserRouter([
2021
{
@@ -73,6 +74,10 @@ const router = createBrowserRouter([
7374
path: "/register-name-dispute",
7475
element: <RegisterNameDispute />,
7576
},
77+
{
78+
path: "/request-reserved-name",
79+
element: <RequestReservedName />,
80+
},
7681
],
7782
},
7883
]);

templates/publisher/request-reserved-name.html

Lines changed: 0 additions & 70 deletions
This file was deleted.

webapp/publisher/snaps/views.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,14 @@ def post_register_name_json():
580580
@publisher_snaps.route("/register-name-dispute")
581581
@login_required
582582
def get_register_name_dispute():
583-
stores = dashboard.get_stores(flask.session)
584-
585583
snap_name = flask.request.args.get("snap-name")
586-
store_id = flask.request.args.get("store")
587-
store_name = logic.get_store_name(store_id, stores)
588584

589585
if not snap_name:
590586
return flask.redirect(
591587
flask.url_for(".get_register_name", snap_name=snap_name)
592588
)
593589
return flask.render_template(
594590
"store/publisher.html",
595-
snap_name=snap_name,
596-
store=store_name,
597591
)
598592

599593

@@ -637,7 +631,7 @@ def get_request_reserved_name():
637631
)
638632
)
639633
return flask.render_template(
640-
"publisher/request-reserved-name.html",
634+
"store/publisher.html",
641635
snap_name=snap_name,
642636
store=store_name,
643637
)

0 commit comments

Comments
 (0)