Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from manGoweb/pr/fixes-9-3
Browse files Browse the repository at this point in the history
Add managers export and offer code
  • Loading branch information
jonasnobile authored Mar 10, 2022
2 parents 1539edd + 2dd627f commit 678ecd9
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 6 deletions.
53 changes: 53 additions & 0 deletions admin/components/ExportOrganizationManagers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as React from "react"
import { Button, Component, useCurrentContentGraphQlClient } from "@contember/admin"

const LIST_ORGANIZATION_MANAGERS_QUERY = `
query {
listOrganizationManager {
id
name
email
phone
}
}
`

type ListOrganizationManagerQueryResult = {
listOrganizationManager: OrganizationManager[]
}

type OrganizationManager = { id: string; name: string, email: string, phone: string }

export const ExportOrganizationManagers = Component(
() => {
const client = useCurrentContentGraphQlClient()
const [prepareDownload, setPrepareDownload] = React.useState<boolean>(false)
const [organizationManagers, setOrganizationManagers] = React.useState<any>(null)
const handler = React.useCallback(async () => {
return await client.sendRequest<ListOrganizationManagerQueryResult>(LIST_ORGANIZATION_MANAGERS_QUERY, {})
}, [client])

if (organizationManagers) {
const csv = organizationManagers.data?.listOrganizationManager?.map((manager: OrganizationManager) => {
return JSON.stringify([manager.name, manager.email, manager.phone])
}).join('\n').replace(/(^\[)|(\]$)/mg, '')
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
return <a href={URL.createObjectURL(blob)} download="organization-managers.csv"><Button distinction="outlined">Stáhnout</Button></a>
} else {
return (
<Button
onClick={async () => {
setPrepareDownload(true)
setTimeout(async () => setOrganizationManagers(await handler()), 1500)
}}
distinction="outlined"
isLoading={prepareDownload}
>
Export
</Button>
)
}
},
() => null,
'ExportOrganizationManagers'
)
2 changes: 1 addition & 1 deletion admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Admin {projectName}</title>
<title>Admin Pomáhej Ukrajině</title>
<script type="module" src="./index.tsx"></script>
</head>
</html>
1 change: 1 addition & 0 deletions admin/pages/offer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const OffersGrid = (
<GenericCell canBeHidden={false} shrunk>
<LinkButton to="editOffer(id: $entity.id)">Otevřít</LinkButton>
</GenericCell>
<TextCell field="code" header="Kód" />
<HasManySelectCell field="assignees" header="Přiřazen" options={'OrganizationManager.name'} />
{/* <GenericCell header="Prohlíží" shrunk>
<CurrentEntityKeyListener>
Expand Down
82 changes: 77 additions & 5 deletions admin/pages/organizations.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import {
Component,
CreatePage,
DataGridPage,
EditIdentity,
EditPage,
useAuthedTenantQuery,
EntityAccessor,
Field,
GenericCell,
HasOneSelectCell,
HiddenField,
LinkButton,
MultiEditPage,
RolesConfig,
SelectField,
TextCell,
TextField,
useField,
useProjectSlug,
useShowToast
useShowToast,
} from "@contember/admin"
import { useInvite } from "../hooks/useInvite"
import * as React from "react"
import { useCallback } from "react"
import { ExportOrganizationManagers } from "../components/ExportOrganizationManagers"

export const organizations = (
<DataGridPage entities="Organization" itemsPerPage={50} rendererProps={{ title: "Organizace", actions: <LinkButton to="organizationCreate">Přidat organizaci</LinkButton> }}>
Expand All @@ -31,8 +37,9 @@ export const organizationCreate = (
)

export const organizationManagerList = (
<DataGridPage entities={'OrganizationManager'} itemsPerPage={100} rendererProps={{
<DataGridPage entities="OrganizationManager" itemsPerPage={100} rendererProps={{
title: 'Pracovníci', actions: <>
<ExportOrganizationManagers />
<LinkButton to={'organizationManagerAdd'}>Pridat</LinkButton>
</>
}}>
Expand All @@ -43,7 +50,7 @@ export const organizationManagerList = (
<GenericCell canBeHidden={false} shrunk>
<LinkButton to="organizationManagerEdit(id: $entity.id)">Detail</LinkButton>
</GenericCell>
</DataGridPage>
</DataGridPage >
)

const useInviteManager = () => {
Expand Down Expand Up @@ -84,12 +91,77 @@ export const organizationManagerAdd = () => (
</CreatePage>
)

const LIST_PROJECT_MEMBER_QUERY = `
query ListProjectMembers($projectSlug: String!) {
projectBySlug(slug: $projectSlug) {
id
members {
identity {
id
person {
id
}
}
}
}
}
`

type ListProjectMembers = {
projectBySlug: {
id: string
members: {
identity: {
id: string
person: {
id: string
}
}
}[]
}
}

const rolesConfig: RolesConfig = {
admin: {
name: 'organizationManager',
variables: {
personID: {
render: () => null,
}
},
}
}

const EditUser = Component(
() => {
const project = useProjectSlug()
const personId = useField<string>('personId').value
const { state: query } = useAuthedTenantQuery<ListProjectMembers, {}>(LIST_PROJECT_MEMBER_QUERY, { projectSlug: project })

if (!personId || !project || query.state !== 'success') {
return null
}

const currentMember = query.data.projectBySlug.members.find(member => member.identity?.person?.id === personId)

if (!currentMember) {
return null
}

return <EditIdentity project={project} rolesConfig={rolesConfig} identityId={currentMember.identity.id} userListLink={'tenantUsers'} />
},
() => (
<Field field="personId" />
),
'EditUser'
)

export const organizationManagerEdit = () => (
<EditPage entity={'OrganizationManager(id = $id)'}>
<EditPage entity={'OrganizationManager(id = $id)'} rendererProps={{ title: 'Pracovník' }}>
<SelectField label={'Organizace'} options={'Organization.name'} field={'organization'} />
<TextField field={'name'} label={'Jméno'} />
<TextField field={'email'} label={'E-mail'} />
<TextField field={'phone'} label={'Telefon'} />
<EditUser />
</EditPage>
)
61 changes: 61 additions & 0 deletions api/migrations/2022-03-09-124902-add-offer-code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"formatVersion": 3,
"modifications": [
{
"modification": "createColumn",
"entityName": "Offer",
"field": {
"name": "code",
"columnName": "code",
"nullable": true,
"type": "String",
"columnType": "text"
}
},
{
"modification": "createUniqueConstraint",
"entityName": "Offer",
"unique": {
"fields": [
"code"
],
"name": "unique_Offer_code_96f2b3"
}
},
{
"modification": "patchAclSchema",
"patch": [
{
"op": "add",
"path": "/roles/admin/entities/Offer/operations/create/code",
"value": true
},
{
"op": "add",
"path": "/roles/admin/entities/Offer/operations/update/code",
"value": true
},
{
"op": "add",
"path": "/roles/admin/entities/Offer/operations/read/code",
"value": true
},
{
"op": "add",
"path": "/roles/volunteer/entities/Offer/operations/update/code",
"value": "self"
},
{
"op": "add",
"path": "/roles/volunteer/entities/Offer/operations/read/code",
"value": "self"
},
{
"op": "add",
"path": "/roles/organizationManager/entities/Offer/operations/read/code",
"value": true
}
]
}
]
}
1 change: 1 addition & 0 deletions api/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class VolunteerDistrict {
}

export class Offer {
code = def.stringColumn().unique()
volunteer = def.manyHasOne(Volunteer, 'offers').notNull()
type = def.manyHasOne(OfferType, 'offers').notNull()
internalNote = def.stringColumn().notNull().default('')
Expand Down

0 comments on commit 678ecd9

Please sign in to comment.