Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions components/settings/general/form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import axios from "axios";
import React from "react";
import type toast from "react-hot-toast";
import { useRecoilState } from "recoil";
import SwitchComponenet from "@/components/switch";
import { workspacestate } from "@/state";
import { FC } from '@/types/settingsComponent'
import { IconForms } from "@tabler/icons-react";

type props = {
triggerToast: typeof toast;
}

const Forms: FC<props> = (props) => {
const triggerToast = props.triggerToast;
const [workspace, setWorkspace] = useRecoilState(workspacestate);

return (
<div className="flex items-center justify-between px-5 py-4">
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg">
<IconForms size={18} className="text-primary" />
</div>
<div>
<p className="text-sm font-medium text-zinc-900 dark:text-white">Forms</p>
<p className="text-xs text-zinc-500 dark:text-zinc-400">Create, customize, and manage workspace forms for collecting structured data, submissions, and user input across your workspace</p>
</div>
</div>
<SwitchComponenet
checked={workspace.settings?.policiesEnabled}
label=""
classoverride="mt-0"
/>
Comment on lines +29 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Forms toggle is wired to the wrong setting and has no update path

Line 30 binds to workspace.settings?.policiesEnabled, so this switch reflects Policies state, not Forms state. Also, no onChange is passed, so users cannot actually toggle Forms behavior from this panel.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/settings/general/form.tsx` around lines 29 - 33, The
SwitchComponenet is bound to the wrong setting and lacks an update mechanism.
Change the checked prop from workspace.settings?.policiesEnabled to the correct
Forms-related setting (likely workspace.settings?.formsEnabled or similar), and
add an onChange handler that updates the Forms setting when the user toggles the
switch. This ensures the component reflects the actual Forms state and allows
users to change it from the settings panel.

</div>
);
};

Forms.title = "Forms";

export default Forms;
3 changes: 2 additions & 1 deletion components/settings/general/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Guide from './guides'
import Alliances from './allies'
import Activity from './activity'
import home from './home'
import Forms from './form';
import Sessions from './sessions'
import Leaderboard from './leaderboard'
import Notices from './notices'
Expand All @@ -11,4 +12,4 @@ import Policies from './policies'
import AuditLogs from './logs'
import Admin from './admin'
import Other from './other'
export { home, Color, Guide, Alliances, Sessions, Activity, Leaderboard, AuditLogs, Policies, Notices, Resignations, Admin, Other };
export { home, Color, Guide, Forms, Alliances, Sessions, Activity, Leaderboard, AuditLogs, Policies, Notices, Resignations, Admin, Other };
52 changes: 52 additions & 0 deletions pages/api/forms/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Orbit Forms
* Licensed under GPL-3.0 (see LICENSE for details)
*
* Helpers to make life easier in the other scripts
*
*
* @module api/forms
* @author BuddyWinte
* @since 2.1.10-beta20
*/

type Permission = string;
interface Role {
permissions: Permission[];
}
interface UserWithRoles {
roles: Role[];
}

/**
* Checks if a user has a given permission.
*
* Supports:
* - Exact matches: "Form.View"
* - Wildcards: "Form.*"
*
* @returns true if the user has permissions
* @returns false if the user doesn't have permissions
* @readonly
*/
export function hasPerms(
user: UserWithRoles,
permission: string
): boolean {
if (!user?.roles?.length) return false;
for (const role of user.roles) {
if (!role?.permissions?.length) continue;

for (const perm of role.permissions) {
if (perm === permission) return true;
if (perm.endsWith(".*")) {
const prefix = perm.slice(0,-2);
if (permission.startsWith(prefix + ".")) {
return true;
}
}
}
}

return false;
}
21 changes: 21 additions & 0 deletions pages/api/forms/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Orbit Forms
* Licensed under GPL-3.0 (see LICENSE for details)
*
* Form collection endpoint.
* Used for listing existing forms and creating new forms.
*
* Routes:
* GET /api/forms
* POST /api/forms
*
* Permissions:
* - Forms.View
* - Forms.Create
*
* @module api/forms
* @author BuddyWinte
* @since 2.1.10-beta20
*/

import { withAuth } from "@/lib/withAuth";
20 changes: 20 additions & 0 deletions pages/api/forms/specific.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Orbit Forms
* Licensed under GPL-3.0 (see LICENSE for details)
*
* Form collection endpoint.
* Used for listing existing forms and creating new forms.
*
* Routes:
* GET /api/forms/:formId
* PATCH /api/forms/:formId
* DELETE /api/forms/:formId
*
* Permissions:
* - Forms.View
* - Forms.Create
*
* @module api/forms
* @author BuddyWinte
* @since 2.1.10-beta20
*/
Comment on lines +1 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "specific.ts" -path "*/api/forms/*" -type f

Repository: PlanetaryOrbit/orbit

Length of output: 94


🏁 Script executed:

cat pages/api/forms/specific.ts

Repository: PlanetaryOrbit/orbit

Length of output: 450


Add default handler export to complete the API route

File contains only module documentation with no handler function. Next.js Pages Router API routes require a default export; without it, the /api/forms/:formId endpoint is non-functional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/api/forms/specific.ts` around lines 1 - 20, The file
pages/api/forms/specific.ts contains only documentation but lacks the required
default export handler function for the Next.js Pages Router API route. Add a
default export async function that accepts the standard Next.js request and
response objects (req and res parameters), and implement handlers for the three
HTTP methods mentioned in the documentation: GET, PATCH, and DELETE for the
/api/forms/:formId endpoint. The function should check the req.method property
to route to the appropriate handler logic for each HTTP verb.

Loading
Loading