-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context actions in empty view for object and space creation
- Loading branch information
Showing
11 changed files
with
149 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { apiFetch } from "../helpers/api"; | ||
import { apiEndpoints } from "../helpers/constants"; | ||
|
||
export async function createSpace(objectData: { name: string }): Promise<void> { | ||
export async function createSpace(space: { name: string }): Promise<void> { | ||
const { url, method } = apiEndpoints.createSpace; | ||
|
||
await apiFetch(url, { | ||
method: method, | ||
body: JSON.stringify({ name: objectData.name }), | ||
body: JSON.stringify({ name: space.name }), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Action, ActionPanel, Form, Icon, showToast, Toast } from "@raycast/api"; | ||
import { useState } from "react"; | ||
import { createSpace } from "../api/createSpace"; | ||
|
||
export default function CreateSpaceForm() { | ||
const [spaceName, setSpaceName] = useState(""); | ||
|
||
const handleSubmit = async () => { | ||
if (!spaceName) { | ||
showToast(Toast.Style.Failure, "Space name is required"); | ||
return; | ||
} | ||
|
||
try { | ||
await createSpace({ name: spaceName }); | ||
showToast(Toast.Style.Success, "Space created successfully"); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
showToast(Toast.Style.Failure, "Failed to create space", error.message); | ||
} else { | ||
showToast(Toast.Style.Failure, "Failed to create space", "Unknown error"); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Form | ||
actions={ | ||
<ActionPanel> | ||
<Action.SubmitForm title="Create Space" icon={Icon.Plus} onSubmit={handleSubmit} /> | ||
</ActionPanel> | ||
} | ||
> | ||
<Form.TextField | ||
id="spaceName" | ||
title="Space Name" | ||
placeholder="Enter space name" | ||
value={spaceName} | ||
onChange={setSpaceName} | ||
/> | ||
</Form> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Action, ActionPanel, Icon, List } from "@raycast/api"; | ||
import Command, { CreateObjectFormValues } from "../create-object"; | ||
|
||
type EmptyViewObjectProps = { | ||
title: string; | ||
contextValues: CreateObjectFormValues; | ||
}; | ||
|
||
export default function EmptyViewObject({ title, contextValues }: EmptyViewObjectProps) { | ||
const draftValues: CreateObjectFormValues = { | ||
space: contextValues.space, | ||
type: contextValues.type, | ||
list: contextValues.list, | ||
name: contextValues.name, | ||
icon: contextValues.icon, | ||
description: contextValues.description, | ||
body: contextValues.body, | ||
source: contextValues.source, | ||
}; | ||
|
||
return ( | ||
<List.EmptyView | ||
title={title} | ||
description="Create a new object by pressing ⏎" | ||
actions={ | ||
<ActionPanel> | ||
<Action.Push title="Create Object" target={<Command draftValues={draftValues} />} icon={Icon.Plus} /> | ||
Check failure on line 27 in src/components/EmptyViewObject.tsx
|
||
</ActionPanel> | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Action, ActionPanel, Icon, List } from "@raycast/api"; | ||
import CreateSpaceForm from "./CreateSpaceForm"; | ||
|
||
export default function EmptyViewSpace({ title }: { title: string }) { | ||
return ( | ||
<List.EmptyView | ||
title={title} | ||
description="Create a new space by pressing ⏎" | ||
actions={ | ||
<ActionPanel> | ||
<Action.Push title="Create Space" target={<CreateSpaceForm />} icon={Icon.Plus} /> | ||
</ActionPanel> | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters