diff --git a/src/app/api/Intents.ts b/src/app/api/Intents.ts new file mode 100644 index 000000000..0c42fde76 --- /dev/null +++ b/src/app/api/Intents.ts @@ -0,0 +1,95 @@ +import { + axiosDelete, + axiosGet, + axiosPost, + axiosPut, +} from '@/services/apiRequests' + +import { AxiosResponse } from 'axios' +import { apiRoutes } from '@/config/apiRoutes' +import { getHeaderConfigs } from '@/config/GetHeaderConfigs' + +interface IPagination { + page: number + itemPerPage: number + search?: string + sortBy?: string + sortingOrder?: string +} + +export const getAllIntents = async ( + ecosystemId: string, + options: IPagination, +): Promise => { + const url = `${apiRoutes.intents.root}${apiRoutes.Ecosystem.root}/${ecosystemId}?pageSize=${options.itemPerPage}&pageNumber=${options.page}&search=${options.search}&sortBy=${options.sortingOrder}&sortField=${options.sortBy}` + const axiosPayload = { + url, + config: getHeaderConfigs(), + } + + try { + return await axiosGet(axiosPayload) + } catch (error) { + const err = error as Error + return err?.message + } +} + +export const createIntent = async ( + ecosystemId: string, + payload: { name: string; description: string }, +): Promise => { + const url = `${apiRoutes.intents.root}${apiRoutes.Ecosystem.root}/${ecosystemId}` + const axiosPayload = { + url, + payload, + config: getHeaderConfigs(), + } + + try { + return await axiosPost(axiosPayload) + } catch (error) { + const err = error as Error + return err?.message + } +} + +export const updateIntent = async ( + ecosystemId: string, + intentId: string, + data: { name: string; description: string }, +): Promise => { + const url = `${apiRoutes.intents.root}${apiRoutes.Ecosystem.root}/${ecosystemId}/${intentId}` + + const axiosPayload = { + url, + payload: data, + config: getHeaderConfigs(), + } + + try { + return await axiosPut(axiosPayload) + } catch (error) { + const err = error as Error + return err?.message + } +} + +export const deleteIntent = async ( + ecosystemId: string, + intentId: string, +): Promise => { + const url = `${apiRoutes.intents.root}${apiRoutes.Ecosystem.root}/${ecosystemId}/${intentId}` + + const axiosPayload = { + url, + config: getHeaderConfigs(), + } + + try { + return await axiosDelete(axiosPayload) + } catch (error) { + const err = error as Error + return err?.message + } +} diff --git a/src/app/api/ecosystem.ts b/src/app/api/ecosystem.ts index b17000788..9c5cf66e9 100644 --- a/src/app/api/ecosystem.ts +++ b/src/app/api/ecosystem.ts @@ -240,7 +240,7 @@ export const acceptRejectMemberInvitation = async ( } try { - return await axiosPost(axiosPayload) + return await axiosPut(axiosPayload) } catch (error) { const err = error as Error return err?.message diff --git a/src/app/intents/page.tsx b/src/app/intents/page.tsx new file mode 100644 index 000000000..6ebb5d2fe --- /dev/null +++ b/src/app/intents/page.tsx @@ -0,0 +1,10 @@ +import IntentList from '@/features/intents/IntentList' +import React from 'react' + +const page = (): React.JSX.Element => ( +
+ +
+) + +export default page diff --git a/src/common/enums.ts b/src/common/enums.ts index 5afa9ead4..5884ffa78 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -41,6 +41,7 @@ export enum Features { ISSUANCE = 'issuance', VERIFICATION = 'verification', CREATE_CERTIFICATE = 'create_certificate', + ECOSYSTEM = 'ecosystem' } export enum SchemaTypes { @@ -65,6 +66,8 @@ export enum Roles { ISSUER = 'issuer', VERIFIER = 'verifier', MEMBER = 'member', + ECOSYSTEM_LEAD = 'ecosystem lead', + ECOSYSTEM_MEMBER = 'ecosystem member' } export enum OrganizationRoles { diff --git a/src/components/RoleViewButton.tsx b/src/components/RoleViewButton.tsx index 8da56520b..4150fb89d 100644 --- a/src/components/RoleViewButton.tsx +++ b/src/components/RoleViewButton.tsx @@ -50,6 +50,12 @@ const RoleViewButton = ({ roles.includes(Roles.VERIFIER) ) + case Features.ECOSYSTEM: + return ( + + roles.includes(Roles.ECOSYSTEM_LEAD) + ) + default: return roles.includes(Roles.OWNER) || roles.includes(Roles.ADMIN) } diff --git a/src/config/apiRoutes.ts b/src/config/apiRoutes.ts index 22886e6a3..bb7630c9b 100644 --- a/src/config/apiRoutes.ts +++ b/src/config/apiRoutes.ts @@ -24,6 +24,10 @@ export const apiRoutes = { deleteSession: '/auth/sessionId:/sessions', }, + intents: { + root:'/intent' + }, + users: { userProfile: '/users/profile', checkUser: '/users/', diff --git a/src/features/components/SessionManager.tsx b/src/features/components/SessionManager.tsx index 2f91ab613..e7fb7260c 100644 --- a/src/features/components/SessionManager.tsx +++ b/src/features/components/SessionManager.tsx @@ -16,6 +16,7 @@ const preventRedirectOnPaths = [ '/wallet-setup', '/create-did', '/x509-certificate', + '/intents', '/did-details', '/organizations', '/users', diff --git a/src/features/ecosystems/components/Manage.tsx b/src/features/ecosystems/components/Manage.tsx index 2b059d7aa..53cb67484 100644 --- a/src/features/ecosystems/components/Manage.tsx +++ b/src/features/ecosystems/components/Manage.tsx @@ -7,6 +7,7 @@ import { useRouter, useSearchParams } from 'next/navigation' import { ArrowLeft } from 'lucide-react' import { Button } from '@/components/ui/button' import Create from './Create' +import IntentList from '@/features/intents/IntentList' import { Invitaitons } from './Invitations' import { Members } from './Members' import { useAppSelector } from '@/lib/hooks' @@ -14,6 +15,7 @@ import { useAppSelector } from '@/lib/hooks' const Manage = (): JSX.Element => { const [activeTab, setActiveTab] = useState('Invitations') const ecosystemName = useAppSelector((state) => state.ecosystem.name) + const ecosystemId = useAppSelector((state) => state.ecosystem.id) const searchParams = useSearchParams() const showCreateForm = searchParams.get('createNew') === 'true' const router = useRouter() @@ -57,6 +59,7 @@ const Manage = (): JSX.Element => { Members + Intents Create @@ -67,6 +70,10 @@ const Manage = (): JSX.Element => { + + + + void + setIntentDesc: (value: string) => void + setSuccess: (val: string | null) => void + setFailure: (val: string | null) => void + handleSubmit: () => void + resetFormState: () => void +} + +interface IntentFormDialogProps { + open: boolean + setOpen: (open: boolean) => void + formState: IntentFormState + handlers: IntentFormHandlers +} + +const IntentFormDialog = ({ + open, + setOpen, + formState, + handlers, +}: IntentFormDialogProps): JSX.Element => { + const { intentName, intentDesc, isEdit, creating, success, failure } = + formState + const { + setIntentName, + setIntentDesc, + setSuccess, + setFailure, + handleSubmit, + resetFormState, + } = handlers + + return ( + { + setOpen(value) + if (!value) { + resetFormState() + } + }} + > + + + {success && ( + setSuccess(null)} + /> + )} + {failure && ( + setFailure(null)} + /> + )} + + {isEdit ? 'Update Intent' : 'Create Intent'} + + + +
+
+ + setIntentName(e.target.value)} + placeholder="Enter intent name" + className="focus:ring-primary w-full rounded-md border px-3 py-2 text-sm outline-none focus:ring-2" + /> +
+ +
+ +