Skip to content

Commit 227debd

Browse files
committed
fixes
1 parent e2a7db4 commit 227debd

File tree

4 files changed

+442
-111
lines changed

4 files changed

+442
-111
lines changed

app/page.tsx

+90-38
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function Home() {
3030
throw new Error("Failed to get blog post collection id");
3131
}
3232
try {
33-
const data = await basehub({ draft: true, token: getToken() }).raw({
33+
const data = await basehub({ token: await getToken() }).raw({
3434
query: `{ blogPosts { _id } }`,
3535
});
3636
// @ts-ignore
@@ -41,38 +41,66 @@ export default async function Home() {
4141
return dostuff(retryCount++);
4242
} else {
4343
// means the collection doesn't exist. we'll create it.
44-
const result = await basehub({ token: getToken() }).mutation({
44+
const result = await basehub({ token: await getToken() }).mutation({
4545
transaction: {
4646
__args: {
47-
data: {
48-
type: "create",
49-
data: {
50-
type: "collection",
51-
title: "Blog Posts",
52-
template: [
53-
{
54-
type: "text",
55-
title: "Excerpt",
56-
isRequired: true,
57-
},
58-
{
59-
type: "date",
60-
title: "Date",
61-
isRequired: true,
62-
},
63-
{
64-
type: "image",
65-
title: "Cover Image",
66-
},
67-
{
68-
type: "rich-text",
69-
title: "Body",
70-
isRequired: true,
71-
formatting: "all",
72-
},
73-
],
47+
data: [
48+
{
49+
type: "create",
50+
data: {
51+
type: "collection",
52+
title: "Authors",
53+
transactionId: "authors",
54+
template: [
55+
{
56+
type: "text",
57+
title: "Role",
58+
},
59+
{
60+
type: "image",
61+
title: "Avatar",
62+
},
63+
],
64+
},
7465
},
75-
},
66+
{
67+
type: "create",
68+
data: {
69+
type: "collection",
70+
title: "Blog Posts",
71+
template: [
72+
{
73+
type: "text",
74+
title: "Excerpt",
75+
isRequired: true,
76+
},
77+
{
78+
type: "date",
79+
title: "Date",
80+
isRequired: true,
81+
},
82+
{
83+
type: "image",
84+
title: "Cover Image",
85+
},
86+
{
87+
type: "reference",
88+
title: "Author(s)",
89+
apiName: "authors",
90+
allowedComponents: ["authors"],
91+
isRequired: true,
92+
multiple: true,
93+
},
94+
{
95+
type: "rich-text",
96+
title: "Body",
97+
isRequired: true,
98+
formatting: "all",
99+
},
100+
],
101+
},
102+
},
103+
],
76104
},
77105
message: true,
78106
status: true,
@@ -201,12 +229,12 @@ export default async function Home() {
201229
}}
202230
</Pump>
203231
<APITokenForm
204-
defaultValue={getToken()}
232+
defaultValue={await getToken()}
205233
action={async (data) => {
206234
"use server";
207235
const token = data.get("token");
208236
if (typeof token === "string") {
209-
cookies().set("basehub-admin-token", token);
237+
(await cookies()).set("basehub-admin-token", token);
210238
}
211239
}}
212240
/>
@@ -217,8 +245,9 @@ export default async function Home() {
217245
"use server";
218246

219247
const collectionId = await getBlogPostCollectionId();
248+
const authorName = faker.person.firstName();
220249

221-
const result = await basehub({ token: getToken() }).mutation({
250+
const result = await basehub({ token: await getToken() }).mutation({
222251
transaction: {
223252
__args: {
224253
autoCommit: "Create a blog post with random data",
@@ -238,6 +267,29 @@ export default async function Home() {
238267
type: "date",
239268
value: new Date().toISOString(),
240269
},
270+
authors: {
271+
type: "reference",
272+
value: {
273+
idempotency: {
274+
key: "title",
275+
value: authorName,
276+
},
277+
type: "instance",
278+
title: authorName,
279+
value: {
280+
role: {
281+
type: "text",
282+
value: faker.person.jobTitle(),
283+
},
284+
avatar: {
285+
type: "image",
286+
value: {
287+
url: faker.image.avatar(),
288+
},
289+
},
290+
},
291+
},
292+
},
241293
body: {
242294
type: "rich-text",
243295
value: {
@@ -280,7 +332,7 @@ export default async function Home() {
280332
const id = formData.get("id");
281333
if (typeof id !== "string") throw new Error("Invalid ID");
282334

283-
const result = await basehub({ token: getToken() }).mutation({
335+
const result = await basehub({ token: await getToken() }).mutation({
284336
transaction: {
285337
__args: {
286338
autoCommit: "Delete a blog post",
@@ -320,7 +372,7 @@ export default async function Home() {
320372
let imageURL: string | undefined;
321373
let imageFileName: string | undefined;
322374
if (image && typeof image === "object" && image.size > 0) {
323-
const result = await basehub({ token: getToken() }).mutation({
375+
const result = await basehub({ token: await getToken() }).mutation({
324376
getUploadSignedURL: {
325377
__args: {
326378
fileName: image.name,
@@ -373,7 +425,7 @@ export default async function Home() {
373425
}),
374426
);
375427

376-
const result = await basehub({ token: getToken() }).mutation({
428+
const result = await basehub({ token: await getToken() }).mutation({
377429
transaction: {
378430
__args: {
379431
autoCommit: "Update a blog post",
@@ -525,8 +577,8 @@ const Form = ({
525577
);
526578
};
527579

528-
function getToken() {
529-
const tokenFromCookie = cookies().get("basehub-admin-token");
580+
async function getToken() {
581+
const tokenFromCookie = (await cookies()).get("basehub-admin-token");
530582
if (tokenFromCookie) return tokenFromCookie.value;
531583

532584
// will fallback to env vars

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "basehub dev & next dev",
6+
"dev": "next dev",
77
"build": "basehub && next build",
88
"start": "next start",
99
"lint": "next lint"
@@ -19,7 +19,7 @@
1919
"class-variance-authority": "^0.7.0",
2020
"clsx": "^2.1.0",
2121
"lucide-react": "^0.344.0",
22-
"next": "14.2.13",
22+
"next": "15.1.6",
2323
"next-themes": "^0.3.0",
2424
"react": "^18",
2525
"react-dom": "^18"

0 commit comments

Comments
 (0)