-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into global-preview
- Loading branch information
Showing
32 changed files
with
672 additions
and
68 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { verifyUserSession } from 'Admin/utils/auth' | ||
import { | ||
getOrganizationById, | ||
removeUserFromOrganization, | ||
} from 'Admin/utils/firebase' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default async function handler( | ||
request: NextApiRequest, | ||
response: NextApiResponse, | ||
) { | ||
try { | ||
const { oid, uid } = request.query as { oid: string; uid: string } | ||
|
||
const organization = await getOrganizationById(oid) | ||
if (!organization) { | ||
return response | ||
.status(404) | ||
.json({ message: 'Organization not found' }) | ||
} | ||
|
||
const requester = await verifyUserSession(request) | ||
|
||
if (!requester || !organization.owners?.includes(requester.uid)) { | ||
return response.status(401).json({ message: 'Unauthorized' }) | ||
} | ||
|
||
switch (request.method) { | ||
case 'DELETE': | ||
await removeUserFromOrganization(oid, uid) | ||
return response.status(200).json({ message: 'User removed' }) | ||
default: | ||
return response | ||
.status(405) | ||
.json({ message: 'Method not allowed' }) | ||
} | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
response.status(400).json({ error: e.message }) | ||
} | ||
} | ||
} |
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,45 @@ | ||
import { verifyUserSession } from 'Admin/utils/auth' | ||
import { | ||
getOrganizationById, | ||
getUsersWithEmailsByUids, | ||
} from 'Admin/utils/firebase' | ||
import { concat } from 'lodash' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default async function handler( | ||
request: NextApiRequest, | ||
response: NextApiResponse, | ||
) { | ||
try { | ||
const { oid } = request.query | ||
|
||
const user = await verifyUserSession(request) | ||
const organization = await getOrganizationById(oid as string) | ||
|
||
if (!user || !organization.owners?.includes(user.uid)) { | ||
return response.status(401).json({ message: 'Unauthorized' }) | ||
} | ||
|
||
if (!organization) { | ||
return response | ||
.status(404) | ||
.json({ message: 'Organization not found' }) | ||
} | ||
|
||
switch (request.method) { | ||
case 'GET': | ||
const members = await getUsersWithEmailsByUids( | ||
concat(organization.owners, organization.editors ?? []), | ||
) | ||
return response.status(200).json({ members }) | ||
default: | ||
return response | ||
.status(405) | ||
.json({ message: 'Method not allowed' }) | ||
} | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
response.status(400).json({ error: e.message }) | ||
} | ||
} | ||
} |
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,54 @@ | ||
import { TavlaError } from 'Admin/types/error' | ||
import { verifyUserSession } from 'Admin/utils/auth' | ||
import { | ||
getUserByEmail, | ||
initializeAdminApp, | ||
inviteUserToOrganization, | ||
userCanEditOrganization, | ||
} from 'Admin/utils/firebase' | ||
import { FeedbackCode } from 'hooks/useFormFeedback' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { TOrganizationID } from 'types/settings' | ||
|
||
initializeAdminApp() | ||
|
||
export default async function handler( | ||
request: NextApiRequest, | ||
response: NextApiResponse, | ||
) { | ||
const withFeedback = (status: number, feedbackCode: FeedbackCode) => { | ||
return response.status(status).json({ feedbackCode }) | ||
} | ||
|
||
try { | ||
const { oid } = request.query as { oid: TOrganizationID } | ||
const { email } = JSON.parse(request.body) as { | ||
email: string | ||
} | ||
|
||
const user = await verifyUserSession(request) | ||
if (!user || !userCanEditOrganization(user.uid, oid)) | ||
return withFeedback(401, 'auth/not-allowed') | ||
|
||
const inviteeId = (await getUserByEmail(email))?.uid | ||
if (!inviteeId) { | ||
return withFeedback(404, 'invite/user-not-found') | ||
} | ||
|
||
return await inviteUserToOrganization(inviteeId, oid) | ||
.then(() => withFeedback(200, 'invite/success')) | ||
.catch((e) => { | ||
if (e instanceof TavlaError) { | ||
switch (e.code) { | ||
case 'ORGANIZATION': | ||
return withFeedback(409, 'invite/already-invited') | ||
} | ||
} | ||
return withFeedback(500, 'error') | ||
}) | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
return withFeedback(500, 'error') | ||
} | ||
} | ||
} |
File renamed without changes.
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
18 changes: 18 additions & 0 deletions
18
next-tavla/src/Admin/scenarios/CreateBoard/components/NextPage.tsx
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,18 @@ | ||
import { PrimaryButton } from '@entur/button' | ||
import { TCreatePage } from 'Admin/types/createBoard' | ||
|
||
function NextPage({ | ||
nextPage, | ||
pushPage, | ||
}: { | ||
nextPage: TCreatePage | ||
pushPage: (page: TCreatePage) => void | ||
}) { | ||
return ( | ||
<PrimaryButton className="w-30" onClick={() => pushPage(nextPage)}> | ||
Neste | ||
</PrimaryButton> | ||
) | ||
} | ||
|
||
export { NextPage } |
23 changes: 23 additions & 0 deletions
23
next-tavla/src/Admin/scenarios/CreateBoard/components/StopPlaceList.tsx
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,23 @@ | ||
import { Paragraph } from '@entur/typography' | ||
import { TBoard } from 'types/settings' | ||
import { StopPlaceChip } from './StopPlaceChip' | ||
|
||
function StopPlaceList({ board }: { board: TBoard }) { | ||
if (board.tiles.length === 0) { | ||
return ( | ||
<Paragraph> | ||
Du har ikke lagt til noen stoppesteder i tavla enda. | ||
</Paragraph> | ||
) | ||
} | ||
|
||
return ( | ||
<div className="flexRow g-2"> | ||
{board.tiles.map((tile) => ( | ||
<StopPlaceChip tile={tile} key={tile.uuid} /> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export { StopPlaceList } |
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 |
---|---|---|
|
@@ -19,3 +19,8 @@ | |
padding: 0.35em 0.5em; | ||
border-radius: 0.5em; | ||
} | ||
|
||
.icon { | ||
height: 2.25em; | ||
width: 2.25em; | ||
} |
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
Oops, something went wrong.