2021-03-12 05:23:46 -05:00
|
|
|
import React, { useEffect } from 'react'
|
|
|
|
import ShareProjectModal from '../js/features/share-project-modal/components/share-project-modal'
|
2021-05-11 10:25:22 -04:00
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const contacts = [
|
|
|
|
// user with edited name
|
|
|
|
{
|
|
|
|
type: 'user',
|
|
|
|
email: 'test-user@example.com',
|
|
|
|
first_name: 'Test',
|
|
|
|
last_name: 'User',
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'Test User',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
// user with default name (email prefix)
|
|
|
|
{
|
|
|
|
type: 'user',
|
|
|
|
email: 'test@example.com',
|
2021-04-27 03:52:58 -04:00
|
|
|
first_name: 'test',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
// no last name
|
|
|
|
{
|
|
|
|
type: 'user',
|
|
|
|
first_name: 'Eratosthenes',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'eratosthenes@example.com',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
// more users
|
|
|
|
{
|
|
|
|
type: 'user',
|
|
|
|
first_name: 'Claudius',
|
|
|
|
last_name: 'Ptolemy',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'ptolemy@example.com',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'user',
|
|
|
|
first_name: 'Abd al-Rahman',
|
|
|
|
last_name: 'Al-Sufi',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'al-sufi@example.com',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'user',
|
|
|
|
first_name: 'Nicolaus',
|
|
|
|
last_name: 'Copernicus',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'copernicus@example.com',
|
|
|
|
},
|
2021-03-12 05:23:46 -05:00
|
|
|
]
|
|
|
|
|
2021-05-11 10:25:22 -04:00
|
|
|
const setupFetchMock = fetchMock => {
|
2021-03-12 05:23:46 -05:00
|
|
|
const delay = 1000
|
|
|
|
|
|
|
|
fetchMock
|
|
|
|
// list contacts
|
|
|
|
.get('express:/user/contacts', { contacts }, { delay })
|
|
|
|
// change privacy setting
|
|
|
|
.post('express:/project/:projectId/settings/admin', 200, { delay })
|
|
|
|
// update project member (e.g. set privilege level)
|
|
|
|
.put('express:/project/:projectId/users/:userId', 200, { delay })
|
|
|
|
// remove project member
|
|
|
|
.delete('express:/project/:projectId/users/:userId', 200, { delay })
|
|
|
|
// transfer ownership
|
|
|
|
.post('express:/project/:projectId/transfer-ownership', 200, {
|
2021-04-27 03:52:58 -04:00
|
|
|
delay,
|
2021-03-12 05:23:46 -05:00
|
|
|
})
|
|
|
|
// send invite
|
|
|
|
.post('express:/project/:projectId/invite', 200, { delay })
|
|
|
|
// delete invite
|
|
|
|
.delete('express:/project/:projectId/invite/:inviteId', 204, {
|
2021-04-27 03:52:58 -04:00
|
|
|
delay,
|
2021-03-12 05:23:46 -05:00
|
|
|
})
|
|
|
|
// resend invite
|
|
|
|
.post('express:/project/:projectId/invite/:inviteId/resend', 200, {
|
2021-04-27 03:52:58 -04:00
|
|
|
delay,
|
2021-03-12 05:23:46 -05:00
|
|
|
})
|
2021-04-30 16:20:16 -04:00
|
|
|
// send analytics event
|
|
|
|
.post('express:/event/:key', 200)
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
const ideWithProject = project => {
|
|
|
|
return {
|
|
|
|
$scope: {
|
|
|
|
$watch: () => () => {},
|
|
|
|
$applyAsync: () => {},
|
2021-04-27 03:52:58 -04:00
|
|
|
project,
|
|
|
|
},
|
2021-03-31 06:44:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
export const LinkSharingOff = args => {
|
2021-05-11 10:25:22 -04:00
|
|
|
useFetchMock(setupFetchMock)
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'private',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const LinkSharingOn = args => {
|
2021-05-11 10:25:22 -04:00
|
|
|
useFetchMock(setupFetchMock)
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'tokenBased',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const LinkSharingLoading = args => {
|
2021-05-11 10:25:22 -04:00
|
|
|
useFetchMock(setupFetchMock)
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
|
|
|
publicAccesLevel: 'tokenBased',
|
2021-04-27 03:52:58 -04:00
|
|
|
tokens: undefined,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const NonAdminLinkSharingOff = args => {
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'private',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return (
|
|
|
|
<ShareProjectModal
|
|
|
|
{...args}
|
|
|
|
isAdmin={false}
|
|
|
|
ide={ideWithProject(project)}
|
|
|
|
/>
|
|
|
|
)
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const NonAdminLinkSharingOn = args => {
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'tokenBased',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return (
|
|
|
|
<ShareProjectModal
|
|
|
|
{...args}
|
|
|
|
isAdmin={false}
|
|
|
|
ide={ideWithProject(project)}
|
|
|
|
/>
|
|
|
|
)
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const RestrictedTokenMember = args => {
|
|
|
|
window.isRestrictedTokenMember = true
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
window.isRestrictedTokenMember = false
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'tokenBased',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const LegacyLinkSharingReadAndWrite = args => {
|
2021-05-11 10:25:22 -04:00
|
|
|
useFetchMock(setupFetchMock)
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'readAndWrite',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const LegacyLinkSharingReadOnly = args => {
|
2021-05-11 10:25:22 -04:00
|
|
|
useFetchMock(setupFetchMock)
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
2021-04-27 03:52:58 -04:00
|
|
|
publicAccesLevel: 'readOnly',
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const LimitedCollaborators = args => {
|
2021-05-11 10:25:22 -04:00
|
|
|
useFetchMock(setupFetchMock)
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
const project = {
|
|
|
|
...args.project,
|
|
|
|
features: {
|
|
|
|
...args.project.features,
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: 3,
|
|
|
|
},
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:44:20 -04:00
|
|
|
return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const project = {
|
|
|
|
_id: 'a-project',
|
|
|
|
name: 'A Project',
|
|
|
|
features: {
|
2021-04-27 03:52:58 -04:00
|
|
|
collaborators: -1, // unlimited
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
publicAccesLevel: 'private',
|
|
|
|
tokens: {
|
|
|
|
readOnly: 'ro-token',
|
2021-04-27 03:52:58 -04:00
|
|
|
readAndWrite: 'rw-token',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
owner: {
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'stories@overleaf.com',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
members: [
|
|
|
|
{
|
|
|
|
_id: 'viewer-member',
|
|
|
|
type: 'user',
|
|
|
|
privileges: 'readOnly',
|
|
|
|
name: 'Viewer User',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'viewer@example.com',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: 'author-member',
|
|
|
|
type: 'user',
|
|
|
|
privileges: 'readAndWrite',
|
|
|
|
name: 'Author User',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'author@example.com',
|
|
|
|
},
|
2021-03-12 05:23:46 -05:00
|
|
|
],
|
|
|
|
invites: [
|
|
|
|
{
|
|
|
|
_id: 'test-invite-1',
|
|
|
|
privileges: 'readOnly',
|
|
|
|
name: 'Invited Viewer',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'invited-viewer@example.com',
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: 'test-invite-2',
|
|
|
|
privileges: 'readAndWrite',
|
|
|
|
name: 'Invited Author',
|
2021-04-27 03:52:58 -04:00
|
|
|
email: 'invited-author@example.com',
|
|
|
|
},
|
|
|
|
],
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2021-03-25 06:11:45 -04:00
|
|
|
title: 'Modals / Share Project',
|
2021-03-12 05:23:46 -05:00
|
|
|
component: ShareProjectModal,
|
|
|
|
args: {
|
|
|
|
show: true,
|
|
|
|
animation: false,
|
|
|
|
isAdmin: true,
|
|
|
|
user: {},
|
2021-04-27 03:52:58 -04:00
|
|
|
project,
|
2021-03-12 05:23:46 -05:00
|
|
|
},
|
|
|
|
argTypes: {
|
2021-04-27 03:52:58 -04:00
|
|
|
handleHide: { action: 'hide' },
|
|
|
|
},
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|