Compare commits
5
Commits
802544e452
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55353e4d46 | ||
|
|
ff177dbaed | ||
|
|
270652f1a8 | ||
|
|
56d8818581 | ||
|
|
ac4b50293e |
No files matched your search
@@ -36,12 +36,16 @@ jobs:
|
|||||||
docker run --rm -v "$PWD/frontend:/src:ro" -w /tmp/app node:22-alpine sh -lc "cp -a /src/. /tmp/app && npm ci && npm run build"
|
docker run --rm -v "$PWD/frontend:/src:ro" -w /tmp/app node:22-alpine sh -lc "cp -a /src/. /tmp/app && npm ci && npm run build"
|
||||||
|
|
||||||
- name: Validate dev compose config
|
- name: Validate dev compose config
|
||||||
|
env:
|
||||||
|
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
cd /docker/FlockPal-dev
|
cd /docker/FlockPal-dev
|
||||||
docker compose -f docker-compose.dev.yaml config --quiet
|
docker compose -f docker-compose.dev.yaml config --quiet
|
||||||
|
|
||||||
- name: Deploy dev
|
- name: Deploy dev
|
||||||
|
env:
|
||||||
|
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
cd /docker/FlockPal-dev
|
cd /docker/FlockPal-dev
|
||||||
@@ -136,12 +140,16 @@ jobs:
|
|||||||
docker run --rm -v "$PWD/frontend:/src:ro" -w /tmp/app node:22-alpine sh -lc "cp -a /src/. /tmp/app && npm ci && npm run build"
|
docker run --rm -v "$PWD/frontend:/src:ro" -w /tmp/app node:22-alpine sh -lc "cp -a /src/. /tmp/app && npm ci && npm run build"
|
||||||
|
|
||||||
- name: Validate prod compose config
|
- name: Validate prod compose config
|
||||||
|
env:
|
||||||
|
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
cd /docker/FlockPal
|
cd /docker/FlockPal
|
||||||
docker compose -f docker-compose.prod.yml config --quiet
|
docker compose -f docker-compose.prod.yml config --quiet
|
||||||
|
|
||||||
- name: Deploy prod
|
- name: Deploy prod
|
||||||
|
env:
|
||||||
|
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
cd /docker/FlockPal
|
cd /docker/FlockPal
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ curl -H "Authorization: Bearer <admin-token>" https://your-host/api/metrics
|
|||||||
- `FRONTEND_URL`
|
- `FRONTEND_URL`
|
||||||
- `BACKEND_URL`
|
- `BACKEND_URL`
|
||||||
- `VITE_API_BASE_URL`
|
- `VITE_API_BASE_URL`
|
||||||
- `MAPBOX_ACCESS_TOKEN`
|
- `MAPBOX_ACCESS_TOKEN` as a Gitea Actions secret for automated deployments (or in `.env` for manual Compose deployments)
|
||||||
- `REDIS_URL`
|
- `REDIS_URL`
|
||||||
- `IMAGE_STORAGE_PROVIDER`
|
- `IMAGE_STORAGE_PROVIDER`
|
||||||
- `S3_ENDPOINT`
|
- `S3_ENDPOINT`
|
||||||
|
|||||||
+74
-19
@@ -1,3 +1,6 @@
|
|||||||
|
import { canUpdateWorkspaceSettings, subscriptionAllowsWrite } from './workspaceAccess.js';
|
||||||
|
import { buildWorkspaceInviteEmail } from './emails/workspaceInviteEmail.js';
|
||||||
|
import { exportFlock } from './repositories/flockExportRepository.js';
|
||||||
import { unassignedBirdMatchSchema, claimBirdSchema } from './birdMembershipSchemas.js';
|
import { unassignedBirdMatchSchema, claimBirdSchema } from './birdMembershipSchemas.js';
|
||||||
import { hasUnassignedBird, removeBirdFromFlock, claimUnassignedBird } from './repositories/birdMembershipRepository.js';
|
import { hasUnassignedBird, removeBirdFromFlock, claimUnassignedBird } from './repositories/birdMembershipRepository.js';
|
||||||
import { behaviorTypeSchema, behaviorOccurrenceSchema, behaviorRangeSchema } from './behaviorSchemas.js';
|
import { behaviorTypeSchema, behaviorOccurrenceSchema, behaviorRangeSchema } from './behaviorSchemas.js';
|
||||||
@@ -1040,14 +1043,6 @@ const normalizeWorkspaceMembershipList = async (userId: string) =>
|
|||||||
|
|
||||||
const isAdminUser = (user: UserRow) => adminEmails.has(normalizeEmail(user.email));
|
const isAdminUser = (user: UserRow) => adminEmails.has(normalizeEmail(user.email));
|
||||||
|
|
||||||
const subscriptionAllowsWrite = (workspace: WorkspaceRow) => {
|
|
||||||
if (workspace.workspace_type === 'rescue') {
|
|
||||||
return workspace.rescue_verification_status === 'approved';
|
|
||||||
}
|
|
||||||
|
|
||||||
return workspace.subscription_status === 'active' || workspace.subscription_status === 'trialing';
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapStripeSubscriptionStatus = (status: Stripe.Subscription.Status): SubscriptionStatus => {
|
const mapStripeSubscriptionStatus = (status: Stripe.Subscription.Status): SubscriptionStatus => {
|
||||||
if (status === 'active' || status === 'trialing' || status === 'past_due' || status === 'canceled' || status === 'unpaid') {
|
if (status === 'active' || status === 'trialing' || status === 'past_due' || status === 'canceled' || status === 'unpaid') {
|
||||||
return status;
|
return status;
|
||||||
@@ -2268,11 +2263,6 @@ const writeBirdTimelineEvent = async ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isBillingOnlyWorkspaceUpdate = (
|
|
||||||
workspace: WorkspaceRow,
|
|
||||||
payload: z.infer<typeof workspaceSchema>,
|
|
||||||
) => workspace.workspace_type === 'standard' && payload.workspaceType === 'standard' && payload.name === workspace.name;
|
|
||||||
|
|
||||||
app.get('/api/health', (_req: Request, res: Response) => {
|
app.get('/api/health', (_req: Request, res: Response) => {
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
@@ -3143,6 +3133,40 @@ app.post('/api/workspaces', requireAuth, requireSessionAuth, async (req: Request
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/workspace/export', requireAuth, requireSessionAuth, async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const parsed = z.object({ birdId: z.string().uuid().optional() }).safeParse(req.query);
|
||||||
|
if (!parsed.success) {
|
||||||
|
res.status(400).json({ error: 'Invalid bird selection.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { birdId } = parsed.data;
|
||||||
|
const data = await exportFlock(req.auth!.workspace.id, birdId);
|
||||||
|
if (birdId && data.birds.length === 0) {
|
||||||
|
res.status(404).json({ error: 'Bird not found in this flock.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const bird of data.birds) {
|
||||||
|
if (bird.photo_object_key) {
|
||||||
|
const config = getS3ImageStorageConfig();
|
||||||
|
if (!config) throw new Error('Image storage is not configured. Unable to export flock photos.');
|
||||||
|
const response = await fetch(getSignedS3ObjectUrl({ config, objectKey: bird.photo_object_key, expiresInSeconds: 300 }), {
|
||||||
|
signal: AbortSignal.timeout(30_000),
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error('Unable to export a flock photo. Please try again.');
|
||||||
|
const contentType = bird.photo_content_type || response.headers.get('content-type') || 'application/octet-stream';
|
||||||
|
bird.photo_data_url = `data:${contentType};base64,${Buffer.from(await response.arrayBuffer()).toString('base64')}`;
|
||||||
|
}
|
||||||
|
delete bird.photo_object_key;
|
||||||
|
}
|
||||||
|
res.setHeader('Cache-Control', 'no-store');
|
||||||
|
res.attachment(`flockpal-${birdId ? `bird-${birdId}` : `flock-${req.auth!.workspace.id}`}-${new Date().toISOString().slice(0, 10)}.json`);
|
||||||
|
res.json(data);
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/api/workspace', requireAuth, async (req: Request, res: Response) => {
|
app.get('/api/workspace', requireAuth, async (req: Request, res: Response) => {
|
||||||
res.json({ workspace: normalizeWorkspace(req.auth!.workspace) });
|
res.json({ workspace: normalizeWorkspace(req.auth!.workspace) });
|
||||||
});
|
});
|
||||||
@@ -3160,10 +3184,7 @@ app.put('/api/workspace', requireAuth, requireSessionAuth, requireWorkspaceRole(
|
|||||||
const billingPlan = resolveBillingPlan(parsed.data.workspaceType, parsed.data.billingPlan ?? currentWorkspace.billing_plan);
|
const billingPlan = resolveBillingPlan(parsed.data.workspaceType, parsed.data.billingPlan ?? currentWorkspace.billing_plan);
|
||||||
const billingInterval = parsed.data.workspaceType === 'rescue' ? 'monthly' : (parsed.data.billingInterval ?? currentWorkspace.billing_interval);
|
const billingInterval = parsed.data.workspaceType === 'rescue' ? 'monthly' : (parsed.data.billingInterval ?? currentWorkspace.billing_interval);
|
||||||
const isConvertingToRescue = currentWorkspace.workspace_type !== 'rescue' && parsed.data.workspaceType === 'rescue';
|
const isConvertingToRescue = currentWorkspace.workspace_type !== 'rescue' && parsed.data.workspaceType === 'rescue';
|
||||||
const canUpdateWorkspace =
|
const canUpdateWorkspace = canUpdateWorkspaceSettings(currentWorkspace, parsed.data, isAdminUser(req.auth!.user));
|
||||||
isAdminUser(req.auth!.user) ||
|
|
||||||
subscriptionAllowsWrite(currentWorkspace) ||
|
|
||||||
isBillingOnlyWorkspaceUpdate(currentWorkspace, parsed.data);
|
|
||||||
|
|
||||||
if (!canUpdateWorkspace) {
|
if (!canUpdateWorkspace) {
|
||||||
res.status(402).json({
|
res.status(402).json({
|
||||||
@@ -3309,6 +3330,37 @@ app.get('/api/workspace/members', requireAuth, async (req: Request, res: Respons
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sendWorkspaceInvitation = async (auth: AuthContext, member: WorkspaceMemberRow) => {
|
||||||
|
if (!mailTransport) return { sent: false, message: 'Access is saved, but email delivery is not configured. Share the sign-in instructions directly.' };
|
||||||
|
try {
|
||||||
|
const result = await mailTransport.sendMail({
|
||||||
|
from: smtpFromName ? `"${smtpFromName}" <${smtpFromEmail}>` : smtpFromEmail,
|
||||||
|
to: member.invite_email,
|
||||||
|
...await buildWorkspaceInviteEmail({
|
||||||
|
name: member.name, email: member.invite_email, inviterName: auth.user.name,
|
||||||
|
flockName: auth.workspace.name, role: member.role, frontendUrl: frontendBaseUrl,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!result.accepted?.length) throw new Error('Invitation email was not accepted.');
|
||||||
|
return { sent: true, message: 'Invitation email sent. Access is ready when they sign in with the invited email address.' };
|
||||||
|
} catch {
|
||||||
|
return { sent: false, message: 'Access is saved, but the invitation email could not be sent. Use Resend invitation to try again.' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
app.post('/api/workspace/members/:memberId/invitation', requireAuth, requireSessionAuth, requireWriteAccess, requireWorkspaceRole(['owner', 'assistant']), async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const member = (await listWorkspaceMembers(req.auth!.workspace.id)).find((entry) => entry.id === req.params.memberId);
|
||||||
|
if (!member) {
|
||||||
|
res.status(404).json({ error: 'Flock member not found.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const invitation = await sendWorkspaceInvitation(req.auth!, member);
|
||||||
|
await writeAuditLog(req.auth!, 'workspace_member.invitation_resent', 'workspace_member', member.id, member.name, { sent: invitation.sent });
|
||||||
|
res.json({ invitation });
|
||||||
|
} catch (error) { next(error); }
|
||||||
|
});
|
||||||
|
|
||||||
app.post('/api/workspace/members', requireAuth, requireWriteAccess, requireWorkspaceRole(['owner', 'assistant']), async (req: Request, res: Response, next: NextFunction) => {
|
app.post('/api/workspace/members', requireAuth, requireWriteAccess, requireWorkspaceRole(['owner', 'assistant']), async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const parsed = workspaceMemberSchema.safeParse(req.body);
|
const parsed = workspaceMemberSchema.safeParse(req.body);
|
||||||
|
|
||||||
@@ -3332,7 +3384,8 @@ app.post('/api/workspace/members', requireAuth, requireWriteAccess, requireWorks
|
|||||||
inviteEmail: member!.invite_email,
|
inviteEmail: member!.invite_email,
|
||||||
role: member!.role,
|
role: member!.role,
|
||||||
});
|
});
|
||||||
res.status(201).json({ member: normalizeWorkspaceMember(member!) });
|
const invitation = await sendWorkspaceInvitation(req.auth!, member!);
|
||||||
|
res.status(201).json({ member: normalizeWorkspaceMember(member!), invitation });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -3745,6 +3798,7 @@ app.post('/api/birds', requireAuth, requireWriteAccess, requireWorkspaceRole(['o
|
|||||||
toWorkspaceId: req.auth!.workspace.id,
|
toWorkspaceId: req.auth!.workspace.id,
|
||||||
locationLabel: bird!.location_label,
|
locationLabel: bird!.location_label,
|
||||||
locationDetails: bird!.location_details,
|
locationDetails: bird!.location_details,
|
||||||
|
eventDate: emptyToNull(parsed.data.locationDate),
|
||||||
createdByUserId: req.auth!.user.id,
|
createdByUserId: req.auth!.user.id,
|
||||||
});
|
});
|
||||||
res.status(201).json({ bird: normalizeBird(bird!) });
|
res.status(201).json({ bird: normalizeBird(bird!) });
|
||||||
@@ -4124,6 +4178,7 @@ app.put('/api/birds/:birdId', requireAuth, requireWriteAccess, requireWorkspaceR
|
|||||||
toWorkspaceId: req.auth!.workspace.id,
|
toWorkspaceId: req.auth!.workspace.id,
|
||||||
locationLabel: bird.location_label,
|
locationLabel: bird.location_label,
|
||||||
locationDetails: bird.location_details,
|
locationDetails: bird.location_details,
|
||||||
|
eventDate: emptyToNull(parsed.data.locationDate),
|
||||||
createdByUserId: req.auth!.user.id,
|
createdByUserId: req.auth!.user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -4140,7 +4195,7 @@ app.put('/api/birds/:birdId', requireAuth, requireWriteAccess, requireWorkspaceR
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.delete('/api/birds/:birdId', requireAuth, requireWriteAccess, requireWorkspaceRole(['owner', 'assistant', 'caregiver']), async (req: Request, res: Response, next: NextFunction) => {
|
app.delete('/api/birds/:birdId', requireAuth, requireWriteAccess, requireWorkspaceRole(['owner', 'assistant']), async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const bird = await getBirdById(req.params.birdId, req.auth!.workspace.id);
|
const bird = await getBirdById(req.params.birdId, req.auth!.workspace.id);
|
||||||
|
|
||||||
|
|||||||
@@ -115,3 +115,20 @@ test('Swagger UI, initialization, assets and specification are served locally wi
|
|||||||
assert.equal(redirect.status, 301);
|
assert.equal(redirect.status, 301);
|
||||||
assert.equal(redirect.headers.get('location'), '/api/docs/');
|
assert.equal(redirect.headers.get('location'), '/api/docs/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('bird removal is restricted to owners and assistants in the API and its documentation', () => {
|
||||||
|
const route = ast.statements.find((statement) =>
|
||||||
|
ts.isExpressionStatement(statement) && ts.isCallExpression(statement.expression) &&
|
||||||
|
statement.expression.expression.getText(ast) === 'app.delete' &&
|
||||||
|
statement.expression.arguments[0]?.getText(ast) === "'/api/birds/:birdId'"
|
||||||
|
);
|
||||||
|
assert.ok(route && ts.isExpressionStatement(route) && ts.isCallExpression(route.expression));
|
||||||
|
const guard = route.expression.arguments.find((arg) =>
|
||||||
|
ts.isCallExpression(arg) && arg.expression.getText(ast) === 'requireWorkspaceRole'
|
||||||
|
);
|
||||||
|
assert.ok(guard && ts.isCallExpression(guard));
|
||||||
|
assert.equal(guard.arguments[0].getText(ast), "['owner', 'assistant']");
|
||||||
|
const description = customerOpenApi.paths['/birds/{birdId}']!.delete!.description!;
|
||||||
|
assert.match(description, /Allowed roles: owner, assistant\./);
|
||||||
|
assert.doesNotMatch(description, /caregiver/);
|
||||||
|
});
|
||||||
@@ -63,7 +63,7 @@ const one = (name: string, model: z.ZodTypeAny) => z.object({ [name]: model });
|
|||||||
const many = (name: string, model: z.ZodTypeAny) => one(name, z.array(model));
|
const many = (name: string, model: z.ZodTypeAny) => one(name, z.array(model));
|
||||||
endpoint({ method: 'get', path: '/workspace', summary: 'Get the token’s workspace', tag: 'Workspace', response: one('workspace', models.workspaceResponse) });
|
endpoint({ method: 'get', path: '/workspace', summary: 'Get the token’s workspace', tag: 'Workspace', response: one('workspace', models.workspaceResponse) });
|
||||||
endpoint({ method: 'get', path: '/workspace/members', summary: 'List workspace members', tag: 'Workspace', response: many('members', models.memberResponse) });
|
endpoint({ method: 'get', path: '/workspace/members', summary: 'List workspace members', tag: 'Workspace', response: many('members', models.memberResponse) });
|
||||||
endpoint({ method: 'post', path: '/workspace/members', summary: 'Add or update a workspace member', tag: 'Workspace', body: registry.register('MemberInput', workspaceMemberSchema), response: one('member', models.memberResponse), roles: ['owner', 'assistant'] });
|
endpoint({ method: 'post', path: '/workspace/members', summary: 'Add or update a workspace member', tag: 'Workspace', body: registry.register('MemberInput', workspaceMemberSchema), response: z.object({ member: models.memberResponse, invitation: z.object({ sent: z.boolean(), message: z.string() }) }), roles: ['owner', 'assistant'], description: 'Saves access and attempts to send a branded invitation email. Check invitation.sent for email submission status; access remains saved if email delivery fails.' });
|
||||||
endpoint({ method: 'put', path: '/workspace/members/{memberId}', summary: 'Change a member’s role', tag: 'Workspace', body: z.object({ role: workspaceRoleSchema }), response: one('member', models.memberResponse), roles: ['owner', 'assistant'], errors: [404], description: 'Only the billing owner can promote collaborators to owner. Additional protections apply to changing your own or the billing owner’s membership.' });
|
endpoint({ method: 'put', path: '/workspace/members/{memberId}', summary: 'Change a member’s role', tag: 'Workspace', body: z.object({ role: workspaceRoleSchema }), response: one('member', models.memberResponse), roles: ['owner', 'assistant'], errors: [404], description: 'Only the billing owner can promote collaborators to owner. Additional protections apply to changing your own or the billing owner’s membership.' });
|
||||||
endpoint({ method: 'delete', path: '/workspace/members/{memberId}', summary: 'Remove a workspace member', tag: 'Workspace', roles: ['owner', 'assistant'], errors: [404], description: 'Protected memberships cannot be removed.' });
|
endpoint({ method: 'delete', path: '/workspace/members/{memberId}', summary: 'Remove a workspace member', tag: 'Workspace', roles: ['owner', 'assistant'], errors: [404], description: 'Protected memberships cannot be removed.' });
|
||||||
endpoint({ method: 'get', path: '/notes', summary: 'List flock notes', tag: 'Notes', response: many('notes', models.noteResponse) });
|
endpoint({ method: 'get', path: '/notes', summary: 'List flock notes', tag: 'Notes', response: many('notes', models.noteResponse) });
|
||||||
@@ -77,7 +77,7 @@ const birdInput = registry.register('BirdInput', birdSchema);
|
|||||||
const birdDescription = 'motivators and demotivators each allow up to three non-empty lines. hatchDay takes precedence over the legacy dateOfBirth field. photoDataUrl accepts an image data URL or HTTP(S) URL; returned photo links may expire.';
|
const birdDescription = 'motivators and demotivators each allow up to three non-empty lines. hatchDay takes precedence over the legacy dateOfBirth field. photoDataUrl accepts an image data URL or HTTP(S) URL; returned photo links may expire.';
|
||||||
endpoint({ method: 'post', path: '/birds', summary: 'Create a bird', tag: 'Birds', body: birdInput, response: one('bird', models.birdResponse), errors: [409], description: birdDescription, example: { name: 'Yoda', species: 'African grey' } });
|
endpoint({ method: 'post', path: '/birds', summary: 'Create a bird', tag: 'Birds', body: birdInput, response: one('bird', models.birdResponse), errors: [409], description: birdDescription, example: { name: 'Yoda', species: 'African grey' } });
|
||||||
endpoint({ method: 'put', path: '/birds/{birdId}', summary: 'Update a bird', tag: 'Birds', body: birdInput, response: one('bird', models.birdResponse), errors: [404, 409], description: `Submit the full editable profile: omitted optional fields may be cleared or reset. ${birdDescription}` });
|
endpoint({ method: 'put', path: '/birds/{birdId}', summary: 'Update a bird', tag: 'Birds', body: birdInput, response: one('bird', models.birdResponse), errors: [404, 409], description: `Submit the full editable profile: omitted optional fields may be cleared or reset. ${birdDescription}` });
|
||||||
endpoint({ method: 'delete', path: '/birds/{birdId}', summary: 'Remove a bird from its flock', tag: 'Birds', errors: [404, 409], description: 'Unassigns the bird without deleting its profile, photo, or care history. Bird-specific notes follow the bird; flock-wide notes and workspace audit logs stay in the old flock. Public sharing is disabled and pending transfers are revoked. An exact band ID match can later bring the bird and its history into a flock.' });
|
endpoint({ method: 'delete', path: '/birds/{birdId}', summary: 'Remove a bird from its flock', roles: ['owner', 'assistant'], tag: 'Birds', errors: [404, 409], description: 'Unassigns the bird without deleting its profile, photo, or care history. Bird-specific notes follow the bird; flock-wide notes and workspace audit logs stay in the old flock. Public sharing is disabled and pending transfers are revoked. An exact band ID match can later bring the bird and its history into a flock.' });
|
||||||
endpoint({ method: 'get', path: '/birds/{birdId}/timeline', summary: 'List bird timeline events', tag: 'Birds', response: many('events', models.timelineResponse), errors: [404] });
|
endpoint({ method: 'get', path: '/birds/{birdId}/timeline', summary: 'List bird timeline events', tag: 'Birds', response: many('events', models.timelineResponse), errors: [404] });
|
||||||
for (const resource of [
|
for (const resource of [
|
||||||
{ path: 'weights', single: 'weight', plural: 'weights', id: 'weightId', tag: 'Weights', input: weightSchema, model: models.weightResponse },
|
{ path: 'weights', single: 'weight', plural: 'weights', id: 'weightId', tag: 'Weights', input: weightSchema, model: models.weightResponse },
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { buildWorkspaceInviteEmail } from './workspaceInviteEmail.js';
|
||||||
|
|
||||||
|
const input = { name: '<Pat>', email: 'pat@example.test', inviterName: 'Alex & Sam', flockName: '<Rescue>', role: 'caregiver' as const, frontendUrl: 'https://flockpal.test/' };
|
||||||
|
|
||||||
|
test('invitation uses branded layout, escaped copy, and email-specific sign-in instructions', async () => {
|
||||||
|
const mail = await buildWorkspaceInviteEmail(input);
|
||||||
|
assert.match(String(mail.html), /<Pat>/);
|
||||||
|
assert.match(String(mail.html), /Alex & Sam/);
|
||||||
|
assert.match(String(mail.html), /<Rescue>/);
|
||||||
|
assert.match(String(mail.html), /cid:flockpal-logo/);
|
||||||
|
assert.equal(mail.attachments?.length, 1);
|
||||||
|
assert.match(mail.text, /Sign in to FlockPal using pat@example.test/);
|
||||||
|
assert.match(mail.text, /cannot remove birds/);
|
||||||
|
assert.match(mail.text, /flock switcher/);
|
||||||
|
assert.match(String(mail.html), /href="https:\/\/flockpal.test\/"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('invitation describes each assigned role and prevents multiline subjects', async () => {
|
||||||
|
for (const role of ['viewer', 'caregiver', 'assistant', 'owner'] as const) {
|
||||||
|
const mail = await buildWorkspaceInviteEmail({ ...input, role, flockName: 'Rescue\r\nFlock' });
|
||||||
|
assert.doesNotMatch(mail.subject, /[\r\n]/);
|
||||||
|
assert.ok(mail.text.includes(role.charAt(0).toUpperCase() + role.slice(1)));
|
||||||
|
if (role === 'viewer') assert.match(mail.text, /cannot edit records/);
|
||||||
|
if (role === 'assistant') assert.match(mail.text, /remove and transfer birds/);
|
||||||
|
if (role === 'owner') assert.match(mail.text, /does not change the billing owner/);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { buildEmailLayout, escapeHtml } from './emailLayout.js';
|
||||||
|
import type { WorkspaceRole } from '../types.js';
|
||||||
|
|
||||||
|
const permissions: Record<WorkspaceRole, string> = {
|
||||||
|
viewer: 'You can view all birds and care histories, and export flock data. You cannot edit records.',
|
||||||
|
caregiver: 'You can view and export flock data, add and edit birds, log daily care, and delete supported care records. You cannot remove birds or manage sharing, billing, or transfers.',
|
||||||
|
assistant: 'You can manage birds and care records, remove and transfer birds, manage collaborators, flock settings and billing, and view the audit log.',
|
||||||
|
owner: 'You have full flock control, including bird removal, transfers, sharing, billing management, memorializing birds, and deleting an empty flock. This does not change the billing owner.',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const buildWorkspaceInviteEmail = async ({ name, email, inviterName, flockName, role, frontendUrl }: {
|
||||||
|
name: string; email: string; inviterName: string; flockName: string; role: WorkspaceRole; frontendUrl: string;
|
||||||
|
}) => {
|
||||||
|
const roleLabel = role.charAt(0).toUpperCase() + role.slice(1);
|
||||||
|
const instructions = `Sign in to FlockPal using ${email}. If you do not have an account, use that email to get started. After signing in, choose ${flockName} in the flock switcher in the navigation or Settings → Flock profile. If you are already signed in and the flock is missing, sign out and sign back in.`;
|
||||||
|
return {
|
||||||
|
subject: `You’re invited to ${flockName.replace(/[\r\n]+/g, ' ')} on FlockPal`,
|
||||||
|
text: `Hi ${name},\n\n${inviterName} has invited you to ${flockName} as a ${roleLabel}.\n\n${permissions[role]}\n\n${instructions}\n\nOpen FlockPal: ${frontendUrl}\n\nIf you were not expecting this invitation, you can ignore this email.`,
|
||||||
|
...await buildEmailLayout({
|
||||||
|
eyebrow: 'Shared flock invitation', headline: `You’re invited to ${flockName}`,
|
||||||
|
contentHtml: `<p>Hi ${escapeHtml(name)},</p><p>${escapeHtml(inviterName)} has invited you to <strong>${escapeHtml(flockName)}</strong> as a <strong>${roleLabel}</strong>.</p><p>${escapeHtml(permissions[role])}</p><p>${escapeHtml(instructions)}</p>`,
|
||||||
|
action: { url: frontendUrl, label: 'Open FlockPal' },
|
||||||
|
footer: 'If you were not expecting this invitation, you can ignore this email.',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { createFlockNote, deleteFlockNote } from './auditRepository.js';
|
||||||
|
import { mockDb } from '../test/mockDb.js';
|
||||||
|
|
||||||
|
test('bird notes require a current, non-memorialized bird in the workspace', async () => {
|
||||||
|
const { calls } = mockDb({ rows: [] });
|
||||||
|
const result = await createFlockNote({ workspaceId: 1, birdId: 'bird-1', body: 'Note', createdByUserId: 'user-1' });
|
||||||
|
assert.equal(result, null);
|
||||||
|
assert.match(calls[0].text, /birds.workspace_id = \$1\s+AND birds.memorialized_at IS NULL/);
|
||||||
|
assert.deepEqual(calls[0].params, [1, 'bird-1', 'Note', 'Note', 'user-1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deleting bird notes preserves memorialized and transferred bird history', async () => {
|
||||||
|
const { calls } = mockDb({ rows: [] });
|
||||||
|
assert.equal(await deleteFlockNote('note-1', 1), null);
|
||||||
|
assert.match(calls[0].text, /bird_id IS NULL OR EXISTS/);
|
||||||
|
assert.match(calls[0].text, /birds.id = flock_notes.bird_id/);
|
||||||
|
assert.match(calls[0].text, /birds.workspace_id = \$2\s+AND birds.memorialized_at IS NULL/);
|
||||||
|
});
|
||||||
@@ -98,6 +98,7 @@ export const createFlockNote = async ({
|
|||||||
FROM birds
|
FROM birds
|
||||||
WHERE birds.id = $2
|
WHERE birds.id = $2
|
||||||
AND birds.workspace_id = $1
|
AND birds.workspace_id = $1
|
||||||
|
AND birds.memorialized_at IS NULL
|
||||||
)
|
)
|
||||||
RETURNING id, workspace_id, bird_id, title, body, created_by_user_id, created_at, updated_at
|
RETURNING id, workspace_id, bird_id, title, body, created_by_user_id, created_at, updated_at
|
||||||
)
|
)
|
||||||
@@ -125,6 +126,12 @@ export const deleteFlockNote = async (noteId: string, workspaceId: number) => {
|
|||||||
`DELETE FROM flock_notes
|
`DELETE FROM flock_notes
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
AND workspace_id = $2
|
AND workspace_id = $2
|
||||||
|
AND (bird_id IS NULL OR EXISTS (
|
||||||
|
SELECT 1 FROM birds
|
||||||
|
WHERE birds.id = flock_notes.bird_id
|
||||||
|
AND birds.workspace_id = $2
|
||||||
|
AND birds.memorialized_at IS NULL
|
||||||
|
))
|
||||||
RETURNING id, title`,
|
RETURNING id, title`,
|
||||||
[noteId, workspaceId],
|
[noteId, workspaceId],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { exportFlock } from './flockExportRepository.js';
|
||||||
|
import { mockDb } from '../test/mockDb.js';
|
||||||
|
|
||||||
|
test('export scopes every history to the selected flock without date or memorial filters', async () => {
|
||||||
|
const data = { formatVersion: 1, birds: [], workspace: { id: 42, name: 'Flock' } };
|
||||||
|
const { calls } = mockDb({ rows: [{ data }] });
|
||||||
|
assert.deepEqual(await exportFlock(42), data);
|
||||||
|
assert.equal(calls.length, 1);
|
||||||
|
const { text, params } = calls[0];
|
||||||
|
assert.deepEqual(params, [42, null]);
|
||||||
|
assert.match(text, /SELECT \* FROM birds WHERE workspace_id = \$1/);
|
||||||
|
for (const table of ['weight_records', 'vet_visits', 'medications', 'medication_administrations', 'behavior_occurrences', 'bird_timeline_events']) {
|
||||||
|
assert.ok(text.includes(`FROM ${table} r JOIN flock_birds b ON b.id = r.bird_id`));
|
||||||
|
}
|
||||||
|
assert.match(text, /FROM flock_notes n WHERE n.workspace_id = \$1/);
|
||||||
|
assert.doesNotMatch(text, /LIMIT|memorialized_at IS NULL|INTERVAL/);
|
||||||
|
assert.doesNotMatch(text, /auth_sessions|integration_tokens|stripe|magic_link/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('single member export restricts profiles, notes, and behavior types to the selected bird', async () => {
|
||||||
|
const birdId = 'd0ab1d12-7859-4a64-a354-dd58bf738b94';
|
||||||
|
const data = { birds: [{ id: birdId }] };
|
||||||
|
const { calls } = mockDb({ rows: [{ data }] });
|
||||||
|
assert.deepEqual(await exportFlock(42, birdId), data);
|
||||||
|
assert.deepEqual(calls[0].params, [42, birdId]);
|
||||||
|
assert.ok(calls[0].text.includes('workspace_id = $1 AND ($2::uuid IS NULL OR id = $2)'));
|
||||||
|
assert.ok(calls[0].text.includes('AND ($2::uuid IS NULL OR n.bird_id IN (SELECT id FROM flock_birds))'));
|
||||||
|
assert.ok(calls[0].text.includes('WHERE ($2::uuid IS NULL AND (t.is_default OR t.workspace_id = $1)) OR EXISTS'));
|
||||||
|
});
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { db } from '../db/client.js';
|
||||||
|
|
||||||
|
type ExportBird = Record<string, unknown> & {
|
||||||
|
photo_object_key?: string | null;
|
||||||
|
photo_content_type?: string | null;
|
||||||
|
photo_data_url?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FlockExport = {
|
||||||
|
formatVersion: number;
|
||||||
|
exportedAt: string;
|
||||||
|
workspace: { id: number; name: string };
|
||||||
|
birds: ExportBird[];
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
// A single statement provides a consistent snapshot, including all dates and memorialized birds.
|
||||||
|
export const exportFlock = async (workspaceId: number, birdId?: string): Promise<FlockExport> => {
|
||||||
|
const birdTables = {
|
||||||
|
weights: 'weight_records',
|
||||||
|
vetVisits: 'vet_visits',
|
||||||
|
medications: 'medications',
|
||||||
|
medicationAdministrations: 'medication_administrations',
|
||||||
|
behaviors: 'behavior_occurrences',
|
||||||
|
timeline: 'bird_timeline_events',
|
||||||
|
};
|
||||||
|
const histories = Object.entries(birdTables).map(([key, table]) =>
|
||||||
|
`'${key}', (SELECT COALESCE(jsonb_agg(to_jsonb(r) ORDER BY r.id), '[]'::jsonb)
|
||||||
|
FROM ${table} r JOIN flock_birds b ON b.id = r.bird_id)`
|
||||||
|
);
|
||||||
|
const result = await db.query<{ data: FlockExport }>(`
|
||||||
|
WITH flock_birds AS (SELECT * FROM birds WHERE workspace_id = $1 AND ($2::uuid IS NULL OR id = $2))
|
||||||
|
SELECT jsonb_build_object(
|
||||||
|
'formatVersion', 1,
|
||||||
|
'exportedAt', CURRENT_TIMESTAMP,
|
||||||
|
'workspace', (SELECT jsonb_build_object('id', id, 'name', name) FROM workspaces WHERE id = $1),
|
||||||
|
'birds', (SELECT COALESCE(jsonb_agg(to_jsonb(b) ORDER BY b.id), '[]'::jsonb) FROM flock_birds b),
|
||||||
|
'notes', (SELECT COALESCE(jsonb_agg(to_jsonb(n) ORDER BY n.id), '[]'::jsonb)
|
||||||
|
FROM flock_notes n WHERE n.workspace_id = $1
|
||||||
|
AND ($2::uuid IS NULL OR n.bird_id IN (SELECT id FROM flock_birds))),
|
||||||
|
'behaviorTypes', (SELECT COALESCE(jsonb_agg(to_jsonb(t) - 'workspace_id' ORDER BY t.id), '[]'::jsonb)
|
||||||
|
FROM behavior_types t WHERE ($2::uuid IS NULL AND (t.is_default OR t.workspace_id = $1)) OR EXISTS (
|
||||||
|
SELECT 1 FROM behavior_occurrences o JOIN flock_birds b ON b.id = o.bird_id
|
||||||
|
WHERE o.behavior_type_id = t.id)),
|
||||||
|
${histories.join(',\n')}
|
||||||
|
) AS data`, [workspaceId, birdId ?? null]);
|
||||||
|
return result.rows[0].data;
|
||||||
|
};
|
||||||
@@ -104,6 +104,7 @@ export const locationSearchSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const birdSchema = z.object({
|
export const birdSchema = z.object({
|
||||||
|
locationDate: dateStringSchema.optional().or(z.literal('')),
|
||||||
name: z.string().trim().min(1).max(120),
|
name: z.string().trim().min(1).max(120),
|
||||||
tagId: z.string().trim().max(80).optional().or(z.literal('')),
|
tagId: z.string().trim().max(80).optional().or(z.literal('')),
|
||||||
species: z.string().trim().min(1).max(120),
|
species: z.string().trim().min(1).max(120),
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { canUpdateWorkspaceSettings, subscriptionAllowsWrite } from '../workspaceAccess.js';
|
||||||
|
import type { WorkspaceRow } from '../types.js';
|
||||||
|
|
||||||
|
type Access = Pick<WorkspaceRow, 'name' | 'workspace_type' | 'subscription_status' | 'rescue_verification_status'>;
|
||||||
|
const household: Access = { name: 'Our flock', workspace_type: 'standard', subscription_status: 'none', rescue_verification_status: 'not_required' };
|
||||||
|
|
||||||
|
test('unsubscribed households can request rescue verification, including a new flock name', () => {
|
||||||
|
for (const subscription_status of ['none', 'past_due', 'canceled', 'unpaid', 'active', 'trialing'] as const) {
|
||||||
|
assert.equal(canUpdateWorkspaceSettings({ ...household, subscription_status }, { name: 'Our rescue', workspaceType: 'rescue' }, false), true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('conversion does not make unverified rescues writable, even with an active subscription', () => {
|
||||||
|
for (const rescue_verification_status of ['pending', 'rejected', 'not_required'] as const) {
|
||||||
|
const rescue: Access = { ...household, workspace_type: 'rescue', subscription_status: 'active', rescue_verification_status };
|
||||||
|
assert.equal(subscriptionAllowsWrite(rescue), false);
|
||||||
|
assert.equal(canUpdateWorkspaceSettings(rescue, { name: rescue.name, workspaceType: 'rescue' }, false), false);
|
||||||
|
}
|
||||||
|
assert.equal(subscriptionAllowsWrite({ ...household, workspace_type: 'rescue', rescue_verification_status: 'approved' }), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('household edits remain subscription gated while billing recovery and admin access still work', () => {
|
||||||
|
assert.equal(subscriptionAllowsWrite(household), false);
|
||||||
|
assert.equal(canUpdateWorkspaceSettings(household, { name: 'Renamed', workspaceType: 'standard' }, false), false);
|
||||||
|
assert.equal(canUpdateWorkspaceSettings(household, { name: household.name, workspaceType: 'standard' }, false), true);
|
||||||
|
assert.equal(canUpdateWorkspaceSettings(household, { name: 'Renamed', workspaceType: 'standard' }, true), true);
|
||||||
|
assert.equal(subscriptionAllowsWrite({ ...household, subscription_status: 'active' }), true);
|
||||||
|
});
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import type { WorkspaceRow, WorkspaceType } from './types.js';
|
||||||
|
|
||||||
|
type WorkspaceAccess = Pick<WorkspaceRow, 'name' | 'workspace_type' | 'subscription_status' | 'rescue_verification_status'>;
|
||||||
|
|
||||||
|
export const subscriptionAllowsWrite = (workspace: WorkspaceAccess) => {
|
||||||
|
if (workspace.workspace_type === 'rescue') {
|
||||||
|
return workspace.rescue_verification_status === 'approved';
|
||||||
|
}
|
||||||
|
return workspace.subscription_status === 'active' || workspace.subscription_status === 'trialing';
|
||||||
|
};
|
||||||
|
|
||||||
|
export const canUpdateWorkspaceSettings = (
|
||||||
|
workspace: WorkspaceAccess,
|
||||||
|
payload: { name: string; workspaceType: WorkspaceType },
|
||||||
|
isAdmin: boolean,
|
||||||
|
) => {
|
||||||
|
// Requesting rescue verification must not require buying a household subscription.
|
||||||
|
// The route still validates onboarding and the repository marks the rescue pending.
|
||||||
|
const requestingRescue = workspace.workspace_type === 'standard' && payload.workspaceType === 'rescue';
|
||||||
|
const billingOnly = workspace.workspace_type === 'standard' && payload.workspaceType === 'standard' && payload.name === workspace.name;
|
||||||
|
return isAdmin || subscriptionAllowsWrite(workspace) || requestingRescue || billingOnly;
|
||||||
|
};
|
||||||
+239
-111
@@ -1,3 +1,5 @@
|
|||||||
|
import { FlockSwitcher } from './FlockSwitcher';
|
||||||
|
import { combineLocationOwnerMarkers } from './birdTimeline';
|
||||||
import { BehaviorJournal } from './BehaviorJournal';
|
import { BehaviorJournal } from './BehaviorJournal';
|
||||||
import { useEffect, useMemo, useState, type CSSProperties, type Dispatch, type SetStateAction } from 'react';
|
import { useEffect, useMemo, useState, type CSSProperties, type Dispatch, type SetStateAction } from 'react';
|
||||||
import birdSilhouette from './assets/bird-silhouette.jpg';
|
import birdSilhouette from './assets/bird-silhouette.jpg';
|
||||||
@@ -288,6 +290,7 @@ type FlockNoteFormState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type BirdFormState = {
|
type BirdFormState = {
|
||||||
|
locationDate: string;
|
||||||
name: string;
|
name: string;
|
||||||
tagId: string;
|
tagId: string;
|
||||||
species: string;
|
species: string;
|
||||||
@@ -841,6 +844,7 @@ const VerifiedLocationSearchField = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const emptyBirdForm: BirdFormState = {
|
const emptyBirdForm: BirdFormState = {
|
||||||
|
locationDate: '',
|
||||||
name: '',
|
name: '',
|
||||||
tagId: '',
|
tagId: '',
|
||||||
species: '',
|
species: '',
|
||||||
@@ -1007,6 +1011,7 @@ const ProviderIcon = ({ providerKey }: { providerKey: AuthProvider['providerKey'
|
|||||||
const sortBirdsByName = (nextBirds: Bird[]) => [...nextBirds].sort((left, right) => left.name.localeCompare(right.name));
|
const sortBirdsByName = (nextBirds: Bird[]) => [...nextBirds].sort((left, right) => left.name.localeCompare(right.name));
|
||||||
|
|
||||||
const toBirdForm = (bird: Bird): BirdFormState => ({
|
const toBirdForm = (bird: Bird): BirdFormState => ({
|
||||||
|
locationDate: '',
|
||||||
name: bird.name,
|
name: bird.name,
|
||||||
tagId: bird.tagId ?? '',
|
tagId: bird.tagId ?? '',
|
||||||
species: bird.species,
|
species: bird.species,
|
||||||
@@ -1184,7 +1189,7 @@ const formatBirdTimelineTitle = (event: BirdTimelineEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'owner_changed') {
|
if (event.eventType === 'owner_changed') {
|
||||||
return 'Owner record changed';
|
return 'Adopted';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'manual_note') {
|
if (event.eventType === 'manual_note') {
|
||||||
@@ -1207,7 +1212,7 @@ const formatBirdTimelineDescription = (event: BirdTimelineEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'owner_changed') {
|
if (event.eventType === 'owner_changed') {
|
||||||
return event.locationLabel ? `Owner changed at ${event.locationLabel}` : 'Owner changed';
|
return event.locationLabel ? `Adopted at ${event.locationLabel}` : 'Adopted';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'manual_note') {
|
if (event.eventType === 'manual_note') {
|
||||||
@@ -1229,7 +1234,7 @@ const formatBirdTimelineSecondary = (event: BirdTimelineEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'owner_changed') {
|
if (event.eventType === 'owner_changed') {
|
||||||
return 'Owner changed without owner name';
|
return 'Adoption recorded without owner names';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@@ -1284,7 +1289,7 @@ const getBirdTimelineGraphLabel = (event: BirdTimelineEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'owner_changed') {
|
if (event.eventType === 'owner_changed') {
|
||||||
return 'Owner changed';
|
return event.locationLabel ? `${compactTimelineLocationLabel(event.locationLabel)} — Adopted` : 'Adopted';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventType === 'transferred') {
|
if (event.eventType === 'transferred') {
|
||||||
@@ -1384,7 +1389,7 @@ const compactTimelineLocationLabel = (label: string) =>
|
|||||||
.join(', ');
|
.join(', ');
|
||||||
|
|
||||||
const getBirdTimelineGraphItems = (bird: Bird, events: BirdTimelineEvent[]): BirdTimelineGraphItem[] => {
|
const getBirdTimelineGraphItems = (bird: Bird, events: BirdTimelineEvent[]): BirdTimelineGraphItem[] => {
|
||||||
const graphEvents: BirdTimelineGraphItem[] = sortBirdTimelineEvents(events)
|
const graphEvents: BirdTimelineGraphItem[] = sortBirdTimelineEvents(combineLocationOwnerMarkers(events, compactTimelineLocationLabel))
|
||||||
.reverse()
|
.reverse()
|
||||||
.filter((event) => event.eventType !== 'profile_created')
|
.filter((event) => event.eventType !== 'profile_created')
|
||||||
.map((event) => ({
|
.map((event) => ({
|
||||||
@@ -1836,6 +1841,20 @@ const formatRescueVerificationStatus = (status: RescueVerificationStatus) => {
|
|||||||
return 'Pending verification';
|
return 'Pending verification';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const workspaceRoleDescriptions: Record<WorkspaceRole, string> = {
|
||||||
|
viewer: 'Can view every bird and their care history, and download flock or individual bird exports. Cannot edit birds or care records.',
|
||||||
|
caregiver: 'Can view and export, add and edit birds, record daily care, and delete supported care records. Cannot remove birds from the flock or manage sharing, billing, or bird transfers.',
|
||||||
|
assistant: 'Can do everything a Caregiver can, plus remove birds from the flock, manage collaborators, flock settings and billing, transfer birds, and view the audit log. Cannot memorialize birds or delete the flock.',
|
||||||
|
owner: 'Can do everything an Assistant can, plus memorialize birds, manage memorial reminders, and delete an empty flock. Owner access does not change the billing owner.',
|
||||||
|
};
|
||||||
|
|
||||||
|
const workspaceRoleLabels: Record<WorkspaceRole, string> = {
|
||||||
|
viewer: 'Viewer — view and export',
|
||||||
|
caregiver: 'Caregiver — birds and daily care',
|
||||||
|
assistant: 'Assistant — flock management',
|
||||||
|
owner: 'Owner — full flock control',
|
||||||
|
};
|
||||||
|
|
||||||
const formatWorkspaceRole = (role: WorkspaceRole) => {
|
const formatWorkspaceRole = (role: WorkspaceRole) => {
|
||||||
if (role === 'owner') {
|
if (role === 'owner') {
|
||||||
return 'Owner';
|
return 'Owner';
|
||||||
@@ -2223,6 +2242,9 @@ function App() {
|
|||||||
|
|
||||||
const [birdImportPreview, setBirdImportPreview] = useState<BirdImportPreview | null>(null);
|
const [birdImportPreview, setBirdImportPreview] = useState<BirdImportPreview | null>(null);
|
||||||
const [birdImportFileName, setBirdImportFileName] = useState('');
|
const [birdImportFileName, setBirdImportFileName] = useState('');
|
||||||
|
const [exportBirdId, setExportBirdId] = useState('');
|
||||||
|
const [exportingFlock, setExportingFlock] = useState(false);
|
||||||
|
const [flockExportError, setFlockExportError] = useState('');
|
||||||
const [birdImportNotice, setBirdImportNotice] = useState('');
|
const [birdImportNotice, setBirdImportNotice] = useState('');
|
||||||
const [importingBirds, setImportingBirds] = useState(false);
|
const [importingBirds, setImportingBirds] = useState(false);
|
||||||
const [memorializeBirdForm, setMemorializeBirdForm] = useState<MemorializeBirdFormState>(emptyMemorializeBirdForm);
|
const [memorializeBirdForm, setMemorializeBirdForm] = useState<MemorializeBirdFormState>(emptyMemorializeBirdForm);
|
||||||
@@ -2234,6 +2256,8 @@ function App() {
|
|||||||
const [savingWorkspace, setSavingWorkspace] = useState(false);
|
const [savingWorkspace, setSavingWorkspace] = useState(false);
|
||||||
const [cancelingRescueRequest, setCancelingRescueRequest] = useState(false);
|
const [cancelingRescueRequest, setCancelingRescueRequest] = useState(false);
|
||||||
const [billingRedirecting, setBillingRedirecting] = useState(false);
|
const [billingRedirecting, setBillingRedirecting] = useState(false);
|
||||||
|
const [invitationNotice, setInvitationNotice] = useState<{ sent: boolean; message: string } | null>(null);
|
||||||
|
const [resendingInvitationId, setResendingInvitationId] = useState<string | null>(null);
|
||||||
const [savingWorkspaceMember, setSavingWorkspaceMember] = useState(false);
|
const [savingWorkspaceMember, setSavingWorkspaceMember] = useState(false);
|
||||||
const [creatingWorkspace, setCreatingWorkspace] = useState(false);
|
const [creatingWorkspace, setCreatingWorkspace] = useState(false);
|
||||||
const [deletingWorkspace, setDeletingWorkspace] = useState(false);
|
const [deletingWorkspace, setDeletingWorkspace] = useState(false);
|
||||||
@@ -2314,9 +2338,10 @@ function App() {
|
|||||||
const [removingWorkspaceMemberId, setRemovingWorkspaceMemberId] = useState('');
|
const [removingWorkspaceMemberId, setRemovingWorkspaceMemberId] = useState('');
|
||||||
const [expandedSettingsSection, setExpandedSettingsSection] = useState<SettingsSection | null>(null);
|
const [expandedSettingsSection, setExpandedSettingsSection] = useState<SettingsSection | null>(null);
|
||||||
|
|
||||||
|
const flockBirds = useMemo(() => sortBirdsByName([...birds, ...memorializedBirds]), [birds, memorializedBirds]);
|
||||||
const selectedBird = useMemo(
|
const selectedBird = useMemo(
|
||||||
() => birds.find((bird) => bird.id === selectedBirdId) ?? null,
|
() => flockBirds.find((bird) => bird.id === selectedBirdId) ?? null,
|
||||||
[birds, selectedBirdId],
|
[flockBirds, selectedBirdId],
|
||||||
);
|
);
|
||||||
const isBillingOwner = Boolean(
|
const isBillingOwner = Boolean(
|
||||||
authSession?.user.email &&
|
authSession?.user.email &&
|
||||||
@@ -3042,7 +3067,7 @@ function App() {
|
|||||||
|
|
||||||
setBirds(nextBirds);
|
setBirds(nextBirds);
|
||||||
setMemorializedBirds(data.memorializedBirds ?? []);
|
setMemorializedBirds(data.memorializedBirds ?? []);
|
||||||
setSelectedBirdId((current) => (current && nextBirds.some((bird) => bird.id === current) ? current : ''));
|
setSelectedBirdId((current) => (current && [...nextBirds, ...(data.memorializedBirds ?? [])].some((bird) => bird.id === current) ? current : ''));
|
||||||
|
|
||||||
if (membersResponse.ok) {
|
if (membersResponse.ok) {
|
||||||
const membersData = (await readJsonSafely<{ members?: WorkspaceMember[] }>(membersResponse)) ?? {};
|
const membersData = (await readJsonSafely<{ members?: WorkspaceMember[] }>(membersResponse)) ?? {};
|
||||||
@@ -3483,7 +3508,7 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleWorkspaceSwitch = async (workspaceId: number, nextActivePage: AppPage = 'overview') => {
|
const handleWorkspaceSwitch = async (workspaceId: number, nextActivePage: AppPage = 'overview') => {
|
||||||
if (!authToken || workspaceId === workspace?.id) {
|
if (!authToken || switchingWorkspaceId !== null || workspaceId === workspace?.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3990,6 +4015,7 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const startEditBird = (bird: Bird) => {
|
const startEditBird = (bird: Bird) => {
|
||||||
|
if (bird.memorializedAt) return;
|
||||||
setSelectedBirdId(bird.id);
|
setSelectedBirdId(bird.id);
|
||||||
setEditingBirdId(bird.id);
|
setEditingBirdId(bird.id);
|
||||||
setBirdEditorOpen(true);
|
setBirdEditorOpen(true);
|
||||||
@@ -4149,6 +4175,34 @@ function App() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setExportBirdId('');
|
||||||
|
setFlockExportError('');
|
||||||
|
setInvitationNotice(null);
|
||||||
|
}, [workspace?.id]);
|
||||||
|
|
||||||
|
const handleFlockExport = async () => {
|
||||||
|
if (exportingFlock) return;
|
||||||
|
setExportingFlock(true);
|
||||||
|
setFlockExportError('');
|
||||||
|
try {
|
||||||
|
const response = await apiFetch(`/workspace/export${exportBirdId ? `?birdId=${encodeURIComponent(exportBirdId)}` : ''}`, authToken);
|
||||||
|
if (!response.ok) throw new Error(await readErrorMessage(response, 'Unable to export flock data.'));
|
||||||
|
const url = URL.createObjectURL(await response.blob());
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = `flockpal-${exportBirdId ? `bird-${exportBirdId}` : `flock-${workspace?.id ?? 'export'}`}-${new Date().toISOString().slice(0, 10)}.json`;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
window.setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
||||||
|
} catch (exportError) {
|
||||||
|
setFlockExportError(exportError instanceof Error ? exportError.message : 'Unable to export flock data.');
|
||||||
|
} finally {
|
||||||
|
setExportingFlock(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleBirdImportSubmit = async () => {
|
const handleBirdImportSubmit = async () => {
|
||||||
if (!birdImportPreview || birdImportPreview.errors.length || importingBirds) {
|
if (!birdImportPreview || birdImportPreview.errors.length || importingBirds) {
|
||||||
return;
|
return;
|
||||||
@@ -4302,7 +4356,7 @@ function App() {
|
|||||||
const response = await apiFetch(isEditing ? `/birds/${editingBirdId}` : '/birds', authToken, {
|
const response = await apiFetch(isEditing ? `/birds/${editingBirdId}` : '/birds', authToken, {
|
||||||
method,
|
method,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel }),
|
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel, locationDate: birdForm.locationDate || getLocalDateString() }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -4902,7 +4956,7 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveBird = async () => {
|
const handleRemoveBird = async () => {
|
||||||
if (!selectedBird || deletingBird) {
|
if (!selectedBird || deletingBird || !['owner', 'assistant'].includes(activeMembership?.role ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4970,7 +5024,7 @@ function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const confirmed = window.confirm(
|
const confirmed = window.confirm(
|
||||||
`Memorialize ${selectedBird.name}?\n\nThis cannot be undone by you. ${selectedBird.name} will become read-only, hidden from the standard flock view, and excluded from the subscription bird count.`,
|
`Memorialize ${selectedBird.name}?\n\nThis cannot be undone by you. ${selectedBird.name} will become read-only, shown softly faded in the flock, and excluded from the subscription bird count.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
@@ -4999,17 +5053,14 @@ function App() {
|
|||||||
const memorializedBird = data.bird;
|
const memorializedBird = data.bird;
|
||||||
setBirds((current) => current.filter((bird) => bird.id !== memorializedBird.id));
|
setBirds((current) => current.filter((bird) => bird.id !== memorializedBird.id));
|
||||||
setMemorializedBirds((current) => sortBirdsByName([...current.filter((bird) => bird.id !== memorializedBird.id), memorializedBird]));
|
setMemorializedBirds((current) => sortBirdsByName([...current.filter((bird) => bird.id !== memorializedBird.id), memorializedBird]));
|
||||||
setSelectedBirdId('');
|
setSelectedBirdId(memorializedBird.id);
|
||||||
|
setBirdEditorOpen(false);
|
||||||
setEditingBirdId('');
|
setEditingBirdId('');
|
||||||
setBirdForm(emptyBirdForm);
|
setBirdForm(emptyBirdForm);
|
||||||
setBirdPhotoName('');
|
setBirdPhotoName('');
|
||||||
setPhotoCrop(null);
|
setPhotoCrop(null);
|
||||||
setPhotoDrag(null);
|
setPhotoDrag(null);
|
||||||
setMemorializeBirdForm(emptyMemorializeBirdForm());
|
setMemorializeBirdForm(emptyMemorializeBirdForm());
|
||||||
setWeights([]);
|
|
||||||
setVetVisits([]);
|
|
||||||
setMedications([]);
|
|
||||||
setMedicationAdministrations([]);
|
|
||||||
setAllBirdWeights((current) => {
|
setAllBirdWeights((current) => {
|
||||||
const next = { ...current };
|
const next = { ...current };
|
||||||
delete next[memorializedBird.id];
|
delete next[memorializedBird.id];
|
||||||
@@ -5817,6 +5868,7 @@ function App() {
|
|||||||
const handleWorkspaceMemberSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const handleWorkspaceMemberSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setError('');
|
setError('');
|
||||||
|
setInvitationNotice(null);
|
||||||
setSavingWorkspaceMember(true);
|
setSavingWorkspaceMember(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -5830,7 +5882,7 @@ function App() {
|
|||||||
throw new Error(await readErrorMessage(response, 'Unable to add rescue team member.'));
|
throw new Error(await readErrorMessage(response, 'Unable to add rescue team member.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = (await readJsonSafely<{ member?: WorkspaceMember }>(response)) ?? {};
|
const data = (await readJsonSafely<{ member?: WorkspaceMember; invitation?: { sent: boolean; message: string } }>(response)) ?? {};
|
||||||
|
|
||||||
if (!data.member) {
|
if (!data.member) {
|
||||||
throw new Error('Unable to add rescue team member.');
|
throw new Error('Unable to add rescue team member.');
|
||||||
@@ -5851,6 +5903,7 @@ function App() {
|
|||||||
return current.map((member) => (member.id === nextMember.id ? nextMember : member));
|
return current.map((member) => (member.id === nextMember.id ? nextMember : member));
|
||||||
});
|
});
|
||||||
setWorkspaceMemberForm(emptyWorkspaceMemberForm);
|
setWorkspaceMemberForm(emptyWorkspaceMemberForm);
|
||||||
|
setInvitationNotice(data.invitation ?? null);
|
||||||
} catch (memberError) {
|
} catch (memberError) {
|
||||||
setError(memberError instanceof Error ? memberError.message : 'Unable to add rescue team member.');
|
setError(memberError instanceof Error ? memberError.message : 'Unable to add rescue team member.');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -5858,6 +5911,21 @@ function App() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleResendInvitation = async (memberId: string) => {
|
||||||
|
setResendingInvitationId(memberId);
|
||||||
|
setInvitationNotice(null);
|
||||||
|
try {
|
||||||
|
const response = await apiFetch(`/workspace/members/${memberId}/invitation`, authToken, { method: 'POST' });
|
||||||
|
if (!response.ok) throw new Error(await readErrorMessage(response, 'Unable to resend invitation.'));
|
||||||
|
const data = await response.json() as { invitation: { sent: boolean; message: string } };
|
||||||
|
setInvitationNotice(data.invitation);
|
||||||
|
} catch (error) {
|
||||||
|
setInvitationNotice({ sent: false, message: error instanceof Error ? error.message : 'Unable to resend invitation.' });
|
||||||
|
} finally {
|
||||||
|
setResendingInvitationId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleUpdateWorkspaceMemberRole = async (memberId: string, role: WorkspaceRole) => {
|
const handleUpdateWorkspaceMemberRole = async (memberId: string, role: WorkspaceRole) => {
|
||||||
setError('');
|
setError('');
|
||||||
setUpdatingWorkspaceMemberId(memberId);
|
setUpdatingWorkspaceMemberId(memberId);
|
||||||
@@ -6258,6 +6326,15 @@ function App() {
|
|||||||
<img className="side-nav-logo" src={flockPalLandingArt} alt="FlockPal" />
|
<img className="side-nav-logo" src={flockPalLandingArt} alt="FlockPal" />
|
||||||
</div>
|
</div>
|
||||||
<aside className="side-nav panel">
|
<aside className="side-nav panel">
|
||||||
|
{showWorkspaceSwitcher ? (
|
||||||
|
<FlockSwitcher
|
||||||
|
entries={authSession.workspaces}
|
||||||
|
currentId={workspace?.id}
|
||||||
|
switching={switchingWorkspaceId !== null}
|
||||||
|
disabled={switchingWorkspaceId !== null || savingWorkspace || deletingWorkspace}
|
||||||
|
onSwitch={(id) => { void handleWorkspaceSwitch(id); }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<div className="page-tabs" role="tablist" aria-label="Main navigation">
|
<div className="page-tabs" role="tablist" aria-label="Main navigation">
|
||||||
<button data-tab="overview" className={`page-tab ${activePage === 'overview' ? 'active' : ''}`} onClick={() => setActivePage('overview')} type="button">
|
<button data-tab="overview" className={`page-tab ${activePage === 'overview' ? 'active' : ''}`} onClick={() => setActivePage('overview')} type="button">
|
||||||
Overview
|
Overview
|
||||||
@@ -6275,26 +6352,6 @@ function App() {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{showWorkspaceSwitcher ? (
|
|
||||||
<section className="workspace-switcher">
|
|
||||||
<div className="workspace-switcher-list">
|
|
||||||
{authSession.workspaces.map((entry) => (
|
|
||||||
<button
|
|
||||||
key={`${entry.workspace.id}-${entry.membership.id}`}
|
|
||||||
className={`workspace-switcher-item ${entry.workspace.id === workspace?.id ? 'active' : ''}`}
|
|
||||||
onClick={() => handleWorkspaceSwitch(entry.workspace.id)}
|
|
||||||
type="button"
|
|
||||||
disabled={switchingWorkspaceId === entry.workspace.id}
|
|
||||||
>
|
|
||||||
<span>{entry.workspace.name}</span>
|
|
||||||
<small>
|
|
||||||
{formatBillingPlanName(entry.workspace.billingPlan)} • {formatWorkspaceRole(entry.membership.role)}
|
|
||||||
</small>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
) : null}
|
|
||||||
<button className="secondary-button" onClick={handleLogout} type="button">
|
<button className="secondary-button" onClick={handleLogout} type="button">
|
||||||
Log out
|
Log out
|
||||||
</button>
|
</button>
|
||||||
@@ -6904,7 +6961,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="bird-list">
|
<div className="bird-list">
|
||||||
{birds.map((bird) => {
|
{flockBirds.map((bird) => {
|
||||||
const weightRangeAlert = outOfRangeBirds.find((alert) => alert.bird.id === bird.id) ?? null;
|
const weightRangeAlert = outOfRangeBirds.find((alert) => alert.bird.id === bird.id) ?? null;
|
||||||
const vetVisitAlertSignature = getVetVisitAlertSignature(bird.id);
|
const vetVisitAlertSignature = getVetVisitAlertSignature(bird.id);
|
||||||
const hasVetVisitAlert = vetVisitDueBirdIds.has(bird.id);
|
const hasVetVisitAlert = vetVisitDueBirdIds.has(bird.id);
|
||||||
@@ -6912,7 +6969,7 @@ function App() {
|
|||||||
return (
|
return (
|
||||||
<article
|
<article
|
||||||
key={bird.id}
|
key={bird.id}
|
||||||
className={`bird-card ${bird.id === selectedBird?.id ? 'active' : ''}`}
|
className={`bird-card ${bird.memorializedAt ? 'memorialized' : ''} ${bird.id === selectedBird?.id ? 'active' : ''}`}
|
||||||
style={bird.id === selectedBird?.id ? { borderColor: bird.chartColor, boxShadow: `0 16px 24px ${bird.chartColor}33` } : undefined}
|
style={bird.id === selectedBird?.id ? { borderColor: bird.chartColor, boxShadow: `0 16px 24px ${bird.chartColor}33` } : undefined}
|
||||||
>
|
>
|
||||||
<button className="bird-card-select" onClick={() => setSelectedBirdId(bird.id)} type="button">
|
<button className="bird-card-select" onClick={() => setSelectedBirdId(bird.id)} type="button">
|
||||||
@@ -6929,11 +6986,14 @@ function App() {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<small>{bird.species}</small>
|
<small>{bird.species}</small>
|
||||||
|
{bird.memorializedAt ? <small className="memorial-label">In memory · Read-only</small> : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<strong>{formatWeight(bird.latestWeightGrams)}</strong>
|
{!bird.memorializedAt || bird.latestWeightGrams !== null ? (
|
||||||
|
<strong>{formatWeight(bird.latestWeightGrams)}</strong>
|
||||||
|
) : null}
|
||||||
</button>
|
</button>
|
||||||
{weightRangeAlert || hasVetVisitAlert ? (
|
{!bird.memorializedAt && (weightRangeAlert || hasVetVisitAlert) ? (
|
||||||
<div className="bird-alert-stack">
|
<div className="bird-alert-stack">
|
||||||
{weightRangeAlert ? (
|
{weightRangeAlert ? (
|
||||||
<span className="bird-alert-badge">
|
<span className="bird-alert-badge">
|
||||||
@@ -7130,27 +7190,6 @@ function App() {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
<div className="settings-inline-header wide-field">
|
|
||||||
<p className="eyebrow">Location</p>
|
|
||||||
<h3>Mappable location</h3>
|
|
||||||
</div>
|
|
||||||
<VerifiedLocationSearchField
|
|
||||||
label="Location"
|
|
||||||
location={birdForm.locationDetails}
|
|
||||||
fallbackLabel={birdForm.locationLabel}
|
|
||||||
searchState={birdLocationSearch}
|
|
||||||
onSearchStateChange={setBirdLocationSearch}
|
|
||||||
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
|
||||||
onSelect={(location) => {
|
|
||||||
const locationLabel = formatVerifiedLocationLabel(location);
|
|
||||||
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
|
||||||
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
|
||||||
}}
|
|
||||||
onClear={() => {
|
|
||||||
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
|
||||||
setBirdLocationSearch(emptyLocationSearchState);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div className="segmented-field wide-field">
|
<div className="segmented-field wide-field">
|
||||||
<span>Gender</span>
|
<span>Gender</span>
|
||||||
<div className="segmented-control" role="radiogroup" aria-label="Bird gender">
|
<div className="segmented-control" role="radiogroup" aria-label="Bird gender">
|
||||||
@@ -7289,6 +7328,37 @@ function App() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
<div className="settings-inline-header wide-field">
|
||||||
|
<p className="eyebrow">Location</p>
|
||||||
|
<h3>Mappable location</h3>
|
||||||
|
</div>
|
||||||
|
<VerifiedLocationSearchField
|
||||||
|
label="Location"
|
||||||
|
location={birdForm.locationDetails}
|
||||||
|
fallbackLabel={birdForm.locationLabel}
|
||||||
|
searchState={birdLocationSearch}
|
||||||
|
onSearchStateChange={setBirdLocationSearch}
|
||||||
|
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
||||||
|
onSelect={(location) => {
|
||||||
|
const locationLabel = formatVerifiedLocationLabel(location);
|
||||||
|
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
||||||
|
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
||||||
|
}}
|
||||||
|
onClear={() => {
|
||||||
|
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
||||||
|
setBirdLocationSearch(emptyLocationSearchState);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<label>
|
||||||
|
Location date
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={birdForm.locationDate || getLocalDateString()}
|
||||||
|
onChange={(event) => setBirdForm({ ...birdForm, locationDate: event.target.value })}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<span className="muted">Date this location took effect. Used when adding a bird or changing its location.</span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className="settings-nested-card">
|
<section className="settings-nested-card">
|
||||||
@@ -7543,9 +7613,9 @@ function App() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<p className="muted">Removing only takes this bird out of your flock. Its profile, photo, notes, and care history are retained and can be brought into a flock later using its exact band ID.</p>
|
<p className="muted">Only Owners and Assistants can remove birds. Removing only takes this bird out of your flock. Its profile, photo, notes, and care history are retained and can be brought into a flock later using its exact band ID.</p>
|
||||||
<div className="button-row">
|
<div className="button-row">
|
||||||
<button className="danger-button" onClick={handleRemoveBird} type="button" disabled={deletingBird}>
|
<button className="danger-button" onClick={handleRemoveBird} type="button" disabled={deletingBird || !['owner', 'assistant'].includes(activeMembership?.role ?? '')}>
|
||||||
{deletingBird ? 'Removing...' : 'Remove from flock'}
|
{deletingBird ? 'Removing...' : 'Remove from flock'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -7657,7 +7727,7 @@ function App() {
|
|||||||
<p className="eyebrow">Flock member</p>
|
<p className="eyebrow">Flock member</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="member-header-actions">
|
<div className="member-header-actions">
|
||||||
{selectedBirdWeightRangeAlert || selectedBirdWeightDropAlerts.length || selectedBirdHasVetVisitAlert ? (
|
{!selectedBird.memorializedAt && (selectedBirdWeightRangeAlert || selectedBirdWeightDropAlerts.length || selectedBirdHasVetVisitAlert) ? (
|
||||||
<div className="bird-alert-stack" aria-label={`Critical alerts for ${selectedBird.name}`}>
|
<div className="bird-alert-stack" aria-label={`Critical alerts for ${selectedBird.name}`}>
|
||||||
{selectedBirdWeightRangeAlert ? (
|
{selectedBirdWeightRangeAlert ? (
|
||||||
<span className="bird-alert-badge">
|
<span className="bird-alert-badge">
|
||||||
@@ -7710,7 +7780,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<section className="profile-hero">
|
<section className={`profile-hero ${selectedBird.memorializedAt ? 'memorialized-profile' : ''}`}>
|
||||||
<img className="profile-photo" src={selectedBird.photoDataUrl || defaultBirdPhoto} alt={`${selectedBird.name}`} />
|
<img className="profile-photo" src={selectedBird.photoDataUrl || defaultBirdPhoto} alt={`${selectedBird.name}`} />
|
||||||
<div className="profile-actions">
|
<div className="profile-actions">
|
||||||
{selectedBird.publicProfileEnabled && selectedBird.publicProfileCode ? (
|
{selectedBird.publicProfileEnabled && selectedBird.publicProfileCode ? (
|
||||||
@@ -7720,7 +7790,7 @@ function App() {
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
<button className="profile-icon-button" onClick={() => startEditBird(selectedBird)} type="button" aria-label={`Edit details for ${selectedBird.name}`} title="Edit details">
|
<button disabled={Boolean(selectedBird.memorializedAt)} className="profile-icon-button" onClick={() => startEditBird(selectedBird)} type="button" aria-label={`Edit details for ${selectedBird.name}`} title="Edit details">
|
||||||
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||||
<path d="M4 20h4l10.5-10.5-4-4L4 16v4Z" />
|
<path d="M4 20h4l10.5-10.5-4-4L4 16v4Z" />
|
||||||
<path d="m13.5 6.5 4 4" />
|
<path d="m13.5 6.5 4 4" />
|
||||||
@@ -7747,7 +7817,8 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div className="bird-detail-tab-panel">
|
{selectedBird.memorializedAt ? <p className="memorial-banner" role="status">In memory of {selectedBird.name}{selectedBird.memorializedOn ? ` · ${formatDate(selectedBird.memorializedOn)}` : ''}. This profile and its care history are read-only.</p> : null}
|
||||||
|
<div className="bird-detail-tab-panel">
|
||||||
{selectedBirdTab === 'info' ? (
|
{selectedBirdTab === 'info' ? (
|
||||||
<div className="flock-member-sections" role="tabpanel">
|
<div className="flock-member-sections" role="tabpanel">
|
||||||
<div className="detail-grid">
|
<div className="detail-grid">
|
||||||
@@ -7797,7 +7868,7 @@ function App() {
|
|||||||
<h2>Medication schedule</h2>
|
<h2>Medication schedule</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="recent-list">{renderMedicationList({ showAdministrationControls: true })}</div>
|
<div className="recent-list">{renderMedicationList({ showAdministrationControls: !selectedBird.memorializedAt })}</div>
|
||||||
</section>
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -7964,7 +8035,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form className="form-panel inline-form" onSubmit={handleWeightSubmit}>
|
{!selectedBird.memorializedAt ? (<form className="form-panel inline-form" onSubmit={handleWeightSubmit}>
|
||||||
<label>
|
<label>
|
||||||
Weight in grams
|
Weight in grams
|
||||||
<input
|
<input
|
||||||
@@ -7995,16 +8066,16 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<div className="button-row care-form-actions">
|
<div className="button-row care-form-actions">
|
||||||
<button className="primary-button" type="submit">
|
<button className="primary-button" disabled={Boolean(selectedBird.memorializedAt)} type="submit">
|
||||||
{editingWeightId ? 'Save weight changes' : 'Save weight'}
|
{editingWeightId ? 'Save weight changes' : 'Save weight'}
|
||||||
</button>
|
</button>
|
||||||
{editingWeightId ? (
|
{editingWeightId ? (
|
||||||
<button className="secondary-button" onClick={handleCancelWeightEdit} type="button">
|
<button className="secondary-button" onClick={handleCancelWeightEdit} disabled={Boolean(selectedBird.memorializedAt)} type="button">
|
||||||
Cancel edit
|
Cancel edit
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>) : null}
|
||||||
<div className="recent-list">
|
<div className="recent-list">
|
||||||
{editableWeights
|
{editableWeights
|
||||||
.map((weight) => (
|
.map((weight) => (
|
||||||
@@ -8013,7 +8084,7 @@ function App() {
|
|||||||
<span>{formatDate(weight.recordedOn)}</span>
|
<span>{formatDate(weight.recordedOn)}</span>
|
||||||
<small>{weight.notes || 'No notes recorded.'}</small>
|
<small>{weight.notes || 'No notes recorded.'}</small>
|
||||||
<div className="button-row">
|
<div className="button-row">
|
||||||
<button className="secondary-button" onClick={() => handleEditWeight(weight)} type="button">
|
<button className="secondary-button" onClick={() => handleEditWeight(weight)} disabled={Boolean(selectedBird.memorializedAt)} type="button">
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -8040,7 +8111,7 @@ function App() {
|
|||||||
setVeterinaryInfoForm(toVeterinaryInfoForm(selectedBird));
|
setVeterinaryInfoForm(toVeterinaryInfoForm(selectedBird));
|
||||||
setEditingVeterinaryInfo(true);
|
setEditingVeterinaryInfo(true);
|
||||||
}}
|
}}
|
||||||
type="button"
|
disabled={Boolean(selectedBird.memorializedAt)} type="button"
|
||||||
aria-label={`Edit veterinary info for ${selectedBird.name}`}
|
aria-label={`Edit veterinary info for ${selectedBird.name}`}
|
||||||
title="Edit veterinary info"
|
title="Edit veterinary info"
|
||||||
>
|
>
|
||||||
@@ -8052,7 +8123,7 @@ function App() {
|
|||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
{editingVeterinaryInfo ? (
|
{editingVeterinaryInfo && !selectedBird.memorializedAt ? (
|
||||||
<form className="form-panel inline-form care-entry-form" onSubmit={handleVeterinaryInfoSubmit}>
|
<form className="form-panel inline-form care-entry-form" onSubmit={handleVeterinaryInfoSubmit}>
|
||||||
<label>
|
<label>
|
||||||
Clinic name
|
Clinic name
|
||||||
@@ -8088,7 +8159,7 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<div className="button-row care-form-actions">
|
<div className="button-row care-form-actions">
|
||||||
<button className="primary-button" type="submit" disabled={savingVeterinaryInfo}>
|
<button className="primary-button" type="submit" disabled={Boolean(selectedBird.memorializedAt) || (savingVeterinaryInfo)}>
|
||||||
{savingVeterinaryInfo ? 'Saving veterinary info...' : 'Save veterinary info'}
|
{savingVeterinaryInfo ? 'Saving veterinary info...' : 'Save veterinary info'}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@@ -8098,7 +8169,7 @@ function App() {
|
|||||||
setEditingVeterinaryInfo(false);
|
setEditingVeterinaryInfo(false);
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={savingVeterinaryInfo}
|
disabled={Boolean(selectedBird.memorializedAt) || (savingVeterinaryInfo)}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
@@ -8134,7 +8205,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form className="form-panel inline-form care-entry-form" onSubmit={handleVetVisitSubmit}>
|
{!selectedBird.memorializedAt ? (<form className="form-panel inline-form care-entry-form" onSubmit={handleVetVisitSubmit}>
|
||||||
<label>
|
<label>
|
||||||
Visit date
|
Visit date
|
||||||
<input
|
<input
|
||||||
@@ -8170,16 +8241,16 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<div className="button-row care-form-actions">
|
<div className="button-row care-form-actions">
|
||||||
<button className="primary-button" type="submit">
|
<button className="primary-button" disabled={Boolean(selectedBird.memorializedAt)} type="submit">
|
||||||
{editingVetVisitId ? 'Save vet visit changes' : 'Save vet visit'}
|
{editingVetVisitId ? 'Save vet visit changes' : 'Save vet visit'}
|
||||||
</button>
|
</button>
|
||||||
{editingVetVisitId ? (
|
{editingVetVisitId ? (
|
||||||
<button className="secondary-button" onClick={handleCancelVetVisitEdit} type="button">
|
<button className="secondary-button" onClick={handleCancelVetVisitEdit} disabled={Boolean(selectedBird.memorializedAt)} type="button">
|
||||||
Cancel edit
|
Cancel edit
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>) : null}
|
||||||
|
|
||||||
<div className="recent-list">
|
<div className="recent-list">
|
||||||
{vetVisits.length ? (
|
{vetVisits.length ? (
|
||||||
@@ -8191,7 +8262,7 @@ function App() {
|
|||||||
</span>
|
</span>
|
||||||
<small>{visit.notes || 'No notes recorded.'}</small>
|
<small>{visit.notes || 'No notes recorded.'}</small>
|
||||||
<div className="button-row">
|
<div className="button-row">
|
||||||
<button className="secondary-button" onClick={() => handleEditVetVisit(visit)} type="button">
|
<button className="secondary-button" onClick={() => handleEditVetVisit(visit)} disabled={Boolean(selectedBird.memorializedAt)} type="button">
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
{editingVetVisitId === visit.id ? (
|
{editingVetVisitId === visit.id ? (
|
||||||
@@ -8199,7 +8270,7 @@ function App() {
|
|||||||
className="secondary-button"
|
className="secondary-button"
|
||||||
onClick={() => handleDeleteVetVisit(visit.id)}
|
onClick={() => handleDeleteVetVisit(visit.id)}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={deletingVetVisitId === visit.id}
|
disabled={Boolean(selectedBird.memorializedAt) || (deletingVetVisitId === visit.id)}
|
||||||
>
|
>
|
||||||
{deletingVetVisitId === visit.id ? 'Deleting...' : 'Delete'}
|
{deletingVetVisitId === visit.id ? 'Deleting...' : 'Delete'}
|
||||||
</button>
|
</button>
|
||||||
@@ -8228,7 +8299,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
<p className="muted">{selectedBirdNotes.length} total</p>
|
<p className="muted">{selectedBirdNotes.length} total</p>
|
||||||
</div>
|
</div>
|
||||||
<form className="form-panel care-entry-form" onSubmit={handleFlockNoteSubmit}>
|
{!selectedBird.memorializedAt ? (<form className="form-panel care-entry-form" onSubmit={handleFlockNoteSubmit}>
|
||||||
<label className="wide-field">
|
<label className="wide-field">
|
||||||
Note
|
Note
|
||||||
<textarea
|
<textarea
|
||||||
@@ -8239,10 +8310,10 @@ function App() {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<button className="primary-button" type="submit" disabled={savingFlockNote}>
|
<button className="primary-button" type="submit" disabled={Boolean(selectedBird.memorializedAt) || (savingFlockNote)}>
|
||||||
{savingFlockNote ? 'Saving...' : 'Save note'}
|
{savingFlockNote ? 'Saving...' : 'Save note'}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>) : null}
|
||||||
<div className="recent-list note-list">
|
<div className="recent-list note-list">
|
||||||
{selectedBirdNotes.length ? (
|
{selectedBirdNotes.length ? (
|
||||||
selectedBirdNotes.map((note) => (
|
selectedBirdNotes.map((note) => (
|
||||||
@@ -8257,7 +8328,7 @@ function App() {
|
|||||||
className="secondary-button"
|
className="secondary-button"
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleDeleteFlockNote(note.id)}
|
onClick={() => handleDeleteFlockNote(note.id)}
|
||||||
disabled={deletingFlockNoteId === note.id}
|
disabled={Boolean(selectedBird.memorializedAt) || (deletingFlockNoteId === note.id)}
|
||||||
>
|
>
|
||||||
{deletingFlockNoteId === note.id ? 'Deleting...' : 'Delete'}
|
{deletingFlockNoteId === note.id ? 'Deleting...' : 'Delete'}
|
||||||
</button>
|
</button>
|
||||||
@@ -8295,10 +8366,10 @@ function App() {
|
|||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<div className="button-row">
|
<div className="button-row">
|
||||||
<button className="primary-button" onClick={() => handleOpenAdoptionReport(false)} type="button" disabled={creatingAdoptionReportCode}>
|
<button className="primary-button" onClick={() => handleOpenAdoptionReport(false)} type="button" disabled={Boolean(selectedBird.memorializedAt) || (creatingAdoptionReportCode)}>
|
||||||
{creatingAdoptionReportCode ? 'Preparing report...' : 'Open adoption report'}
|
{creatingAdoptionReportCode ? 'Preparing report...' : 'Open adoption report'}
|
||||||
</button>
|
</button>
|
||||||
<button className="secondary-button" onClick={() => handleOpenAdoptionReport(true)} type="button" disabled={creatingAdoptionReportCode}>
|
<button className="secondary-button" onClick={() => handleOpenAdoptionReport(true)} type="button" disabled={Boolean(selectedBird.memorializedAt) || (creatingAdoptionReportCode)}>
|
||||||
Print-friendly report
|
Print-friendly report
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -8382,7 +8453,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
) : null;
|
) : null;
|
||||||
})()}
|
})()}
|
||||||
<form className="form-panel inline-form care-entry-form bird-timeline-form" onSubmit={handleBirdTimelineEventSubmit}>
|
{!selectedBird.memorializedAt ? (<form className="form-panel inline-form care-entry-form bird-timeline-form" onSubmit={handleBirdTimelineEventSubmit}>
|
||||||
<label>
|
<label>
|
||||||
Type
|
Type
|
||||||
<select
|
<select
|
||||||
@@ -8403,7 +8474,7 @@ function App() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<option value="location_updated">Location note</option>
|
<option value="location_updated">Location note</option>
|
||||||
<option value="owner_changed">Owner</option>
|
<option value="owner_changed">Adoption</option>
|
||||||
<option value="manual_note">General note</option>
|
<option value="manual_note">General note</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
@@ -8453,8 +8524,8 @@ function App() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>
|
<span>
|
||||||
<strong>Owner changed</strong>
|
<strong>Adopted</strong>
|
||||||
<small>Records a change without owner names.</small>
|
<small>Records an adoption without owner names.</small>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -8471,7 +8542,7 @@ function App() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<button className="primary-button" type="submit" disabled={savingBirdTimelineEvent}>
|
<button className="primary-button" type="submit" disabled={Boolean(selectedBird.memorializedAt) || (savingBirdTimelineEvent)}>
|
||||||
{savingBirdTimelineEvent ? 'Adding...' : 'Add timeline item'}
|
{savingBirdTimelineEvent ? 'Adding...' : 'Add timeline item'}
|
||||||
</button>
|
</button>
|
||||||
{birdTimelineNotice ? (
|
{birdTimelineNotice ? (
|
||||||
@@ -8479,7 +8550,7 @@ function App() {
|
|||||||
{birdTimelineNotice.message}
|
{birdTimelineNotice.message}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
</form>
|
</form>) : null}
|
||||||
<div className="recent-list bird-timeline-list">
|
<div className="recent-list bird-timeline-list">
|
||||||
{birdTimelineEvents.length ? (
|
{birdTimelineEvents.length ? (
|
||||||
birdTimelineEvents.map((event) => (
|
birdTimelineEvents.map((event) => (
|
||||||
@@ -8498,7 +8569,7 @@ function App() {
|
|||||||
) : (
|
) : (
|
||||||
<article className="empty-card">
|
<article className="empty-card">
|
||||||
<strong>No timeline events yet</strong>
|
<strong>No timeline events yet</strong>
|
||||||
<small>New location and owner changes for {selectedBird.name} will appear here.</small>
|
<small>New location changes and adoptions for {selectedBird.name} will appear here.</small>
|
||||||
</article>
|
</article>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -9060,9 +9131,26 @@ function App() {
|
|||||||
{expandedSettingsSection === 'collaborators' ? (
|
{expandedSettingsSection === 'collaborators' ? (
|
||||||
<>
|
<>
|
||||||
<p className="muted">
|
<p className="muted">
|
||||||
Invite other people to help manage this flock. Rescue flocks support teams, and household flocks can also support
|
Give someone access to this flock using their email address. Their role applies to every bird in this flock,
|
||||||
co-caregivers without changing who owns the billing.
|
including memorialized birds. Every role can download flock data. Sharing access does not change the billing owner.
|
||||||
</p>
|
</p>
|
||||||
|
<details className="summary-card">
|
||||||
|
<summary>Compare shared flock roles</summary>
|
||||||
|
<div className="recent-list">
|
||||||
|
{(['viewer', 'caregiver', 'assistant', 'owner'] as const).map((role) => (
|
||||||
|
<div key={role}>
|
||||||
|
<strong>{workspaceRoleLabels[role]}</strong>
|
||||||
|
<p>{workspaceRoleDescriptions[role]}</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<p className="muted">
|
||||||
|
Memorialized bird records remain read-only. Editing also depends on the flock’s subscription or rescue verification status.
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
{invitationNotice ? (
|
||||||
|
<p className={invitationNotice.sent ? 'success-banner' : 'error-banner'} role="status">{invitationNotice.message}</p>
|
||||||
|
) : null}
|
||||||
<form className="form-panel" onSubmit={handleWorkspaceMemberSubmit}>
|
<form className="form-panel" onSubmit={handleWorkspaceMemberSubmit}>
|
||||||
<label>
|
<label>
|
||||||
Team member name
|
Team member name
|
||||||
@@ -9085,6 +9173,7 @@ function App() {
|
|||||||
Role
|
Role
|
||||||
<select
|
<select
|
||||||
value={workspaceMemberForm.role}
|
value={workspaceMemberForm.role}
|
||||||
|
aria-describedby="invite-role-description"
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setWorkspaceMemberForm({
|
setWorkspaceMemberForm({
|
||||||
...workspaceMemberForm,
|
...workspaceMemberForm,
|
||||||
@@ -9092,14 +9181,17 @@ function App() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isBillingOwner ? <option value="owner">Owner</option> : null}
|
{isBillingOwner ? <option value="owner">{workspaceRoleLabels.owner}</option> : null}
|
||||||
<option value="assistant">Assistant</option>
|
<option value="assistant">{workspaceRoleLabels.assistant}</option>
|
||||||
<option value="caregiver">Caregiver</option>
|
<option value="caregiver">{workspaceRoleLabels.caregiver}</option>
|
||||||
<option value="viewer">Viewer</option>
|
<option value="viewer">{workspaceRoleLabels.viewer}</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
<p id="invite-role-description" className="muted" aria-live="polite">
|
||||||
|
{workspaceRoleDescriptions[workspaceMemberForm.role]}
|
||||||
|
</p>
|
||||||
<button className="primary-button" type="submit" disabled={savingWorkspaceMember}>
|
<button className="primary-button" type="submit" disabled={savingWorkspaceMember}>
|
||||||
{savingWorkspaceMember ? 'Adding member...' : 'Add collaborator'}
|
{savingWorkspaceMember ? 'Sending invitation...' : 'Add collaborator and send invitation'}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@@ -9131,6 +9223,7 @@ function App() {
|
|||||||
Role
|
Role
|
||||||
<select
|
<select
|
||||||
value={member.role}
|
value={member.role}
|
||||||
|
aria-describedby={`member-role-description-${member.id}`}
|
||||||
onChange={(event) => handleUpdateWorkspaceMemberRole(member.id, event.target.value as WorkspaceRole)}
|
onChange={(event) => handleUpdateWorkspaceMemberRole(member.id, event.target.value as WorkspaceRole)}
|
||||||
disabled={
|
disabled={
|
||||||
(member.role === 'owner' && !canChangeOwnerRole) ||
|
(member.role === 'owner' && !canChangeOwnerRole) ||
|
||||||
@@ -9138,12 +9231,21 @@ function App() {
|
|||||||
removingWorkspaceMemberId === member.id
|
removingWorkspaceMemberId === member.id
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{member.role === 'owner' || canPromoteToOwner ? <option value="owner">Owner</option> : null}
|
{member.role === 'owner' || canPromoteToOwner ? <option value="owner">{workspaceRoleLabels.owner}</option> : null}
|
||||||
<option value="assistant">Assistant</option>
|
<option value="assistant">{workspaceRoleLabels.assistant}</option>
|
||||||
<option value="caregiver">Caregiver</option>
|
<option value="caregiver">{workspaceRoleLabels.caregiver}</option>
|
||||||
<option value="viewer">Viewer</option>
|
<option value="viewer">{workspaceRoleLabels.viewer}</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
<p id={`member-role-description-${member.id}`} className="muted" aria-live="polite">
|
||||||
|
{workspaceRoleDescriptions[member.role]}
|
||||||
|
</p>
|
||||||
|
{['owner', 'assistant'].includes(activeMembership?.role ?? '') ? (
|
||||||
|
<button className="secondary-button" type="button" onClick={() => handleResendInvitation(member.id)}
|
||||||
|
disabled={resendingInvitationId !== null || removingWorkspaceMemberId === member.id}>
|
||||||
|
{resendingInvitationId === member.id ? 'Sending...' : 'Resend invitation'}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
<button
|
<button
|
||||||
className="danger-button"
|
className="danger-button"
|
||||||
onClick={() => handleRemoveWorkspaceMember(member.id)}
|
onClick={() => handleRemoveWorkspaceMember(member.id)}
|
||||||
@@ -9283,8 +9385,8 @@ function App() {
|
|||||||
<article className="panel form-panel settings-card-bird-import">
|
<article className="panel form-panel settings-card-bird-import">
|
||||||
<div className="panel-header">
|
<div className="panel-header">
|
||||||
<div>
|
<div>
|
||||||
<p className="eyebrow">Import</p>
|
<p className="eyebrow">Flock data</p>
|
||||||
<h2>Bulk Import</h2>
|
<h2>Bulk actions</h2>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
className="secondary-button"
|
className="secondary-button"
|
||||||
@@ -9299,6 +9401,32 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
{expandedSettingsSection === 'bird-import' ? (
|
{expandedSettingsSection === 'bird-import' ? (
|
||||||
<>
|
<>
|
||||||
|
<h3>Bulk export</h3>
|
||||||
|
<p className="muted">
|
||||||
|
Download all information for {workspace?.name ?? 'this flock'}, including active and memorialized bird profiles,
|
||||||
|
photos, all weights, vet visits, medications and doses, behaviors, timeline history, and flock notes.
|
||||||
|
Choose a single flock member to export only their profile and records, including their bird-specific notes.
|
||||||
|
The JSON file preserves your complete records. Export each flock separately if you have multiple flocks.
|
||||||
|
JSON exports cannot be uploaded through the Excel import below.
|
||||||
|
</p>
|
||||||
|
<label>
|
||||||
|
Export scope
|
||||||
|
<select value={exportBirdId} onChange={(event) => setExportBirdId(event.target.value)} disabled={exportingFlock}>
|
||||||
|
<option value="">All flock members</option>
|
||||||
|
{flockBirds.map((bird) => (
|
||||||
|
<option key={bird.id} value={bird.id}>
|
||||||
|
{bird.name}{bird.tagId ? ` — ${bird.tagId}` : ''}{bird.memorializedAt ? ' (In memory)' : ''}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<div className="button-row">
|
||||||
|
<button className="primary-button" type="button" onClick={handleFlockExport} disabled={exportingFlock}>
|
||||||
|
{exportingFlock ? 'Exporting...' : exportBirdId ? 'Export selected flock member' : 'Export all flock data'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{flockExportError ? <p className="error-banner" role="alert">{flockExportError}</p> : null}
|
||||||
|
<h3>Bulk import</h3>
|
||||||
<p className="muted">
|
<p className="muted">
|
||||||
Import the first worksheet from an Excel file. Use one row per weight entry and repeat the Bird Name for rows that belong to the
|
Import the first worksheet from an Excel file. Use one row per weight entry and repeat the Bird Name for rows that belong to the
|
||||||
same profile.
|
same profile.
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
|
type FlockEntry = { workspace: { id: number; name: string }; membership: { role: string } };
|
||||||
|
const roleName = (role: string) => role.charAt(0).toUpperCase() + role.slice(1);
|
||||||
|
|
||||||
|
export function FlockSwitcher({ entries, currentId, switching, disabled, onSwitch }: {
|
||||||
|
entries: FlockEntry[]; currentId?: number; switching: boolean; disabled: boolean; onSwitch: (id: number) => void;
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const container = useRef<HTMLElement>(null);
|
||||||
|
const trigger = useRef<HTMLButtonElement>(null);
|
||||||
|
const current = entries.find((entry) => entry.workspace.id === currentId);
|
||||||
|
|
||||||
|
useEffect(() => { setOpen(false); }, [currentId, disabled]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const closeOutside = (event: PointerEvent) => {
|
||||||
|
if (!container.current?.contains(event.target as Node)) setOpen(false);
|
||||||
|
};
|
||||||
|
document.addEventListener('pointerdown', closeOutside);
|
||||||
|
return () => document.removeEventListener('pointerdown', closeOutside);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="workspace-switcher" aria-label="Flock selection" ref={container}
|
||||||
|
onBlur={(event) => { if (!event.currentTarget.contains(event.relatedTarget)) setOpen(false); }}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Escape' && open) {
|
||||||
|
event.preventDefault();
|
||||||
|
setOpen(false);
|
||||||
|
trigger.current?.focus();
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<span className="workspace-switcher-label">Current flock</span>
|
||||||
|
<button className="flock-switcher-trigger" ref={trigger} type="button" disabled={disabled}
|
||||||
|
aria-expanded={open} aria-controls="flock-switcher-options" onClick={() => setOpen(!open)}>
|
||||||
|
<span className="flock-switcher-avatar" aria-hidden="true">{current?.workspace.name.trim().charAt(0).toUpperCase() || 'F'}</span>
|
||||||
|
<span className="flock-switcher-copy">
|
||||||
|
<strong>{current?.workspace.name ?? 'Choose a flock'}</strong>
|
||||||
|
<small>{current ? roleName(current.membership.role) : 'Switch flocks'}</small>
|
||||||
|
</span>
|
||||||
|
<svg className={`flock-switcher-chevron ${open ? 'is-open' : ''}`} width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true"><path d="m6 9 6 6 6-6" /></svg>
|
||||||
|
</button>
|
||||||
|
<span className="flock-switcher-status" role="status">{switching ? 'Switching flocks…' : ''}</span>
|
||||||
|
{open ? (
|
||||||
|
<div id="flock-switcher-options" className="flock-switcher-options">
|
||||||
|
<p className="flock-switcher-heading">Switch flock</p>
|
||||||
|
{[
|
||||||
|
{ label: 'My flocks', items: entries.filter((entry) => entry.membership.role === 'owner') },
|
||||||
|
{ label: 'Shared with me', items: entries.filter((entry) => entry.membership.role !== 'owner') },
|
||||||
|
].filter((group) => group.items.length).map((group) => (
|
||||||
|
<div className="flock-switcher-group" key={group.label} role="group" aria-label={group.label}>
|
||||||
|
<p>{group.label}</p>
|
||||||
|
{group.items.map((entry) => (
|
||||||
|
<button className="flock-switcher-option" key={entry.workspace.id} type="button"
|
||||||
|
aria-current={entry.workspace.id === currentId ? 'true' : undefined}
|
||||||
|
onClick={() => { setOpen(false); trigger.current?.focus(); onSwitch(entry.workspace.id); }}>
|
||||||
|
<span className="flock-switcher-copy"><strong>{entry.workspace.name}</strong><small>{roleName(entry.membership.role)}</small></span>
|
||||||
|
{entry.workspace.id === currentId ? <span className="flock-switcher-check" aria-label="Current flock">✓</span> : null}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
type LocationEvent = {
|
||||||
|
eventType: string;
|
||||||
|
eventDate: string;
|
||||||
|
createdAt: string;
|
||||||
|
locationLabel: string | null;
|
||||||
|
toWorkspaceId: number | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keep the owner marker when it already represents the same dated location.
|
||||||
|
// The original event list remains unchanged so notes and audit history are retained.
|
||||||
|
export const combineLocationOwnerMarkers = <T extends LocationEvent>(
|
||||||
|
events: T[],
|
||||||
|
normalizeLocation: (location: string) => string,
|
||||||
|
): T[] => {
|
||||||
|
const key = (event: T) => JSON.stringify([
|
||||||
|
event.eventDate || event.createdAt.slice(0, 10),
|
||||||
|
normalizeLocation(event.locationLabel || '').trim().toLowerCase(),
|
||||||
|
event.toWorkspaceId,
|
||||||
|
]);
|
||||||
|
const ownerLocations = new Set(events
|
||||||
|
.filter((event) => event.eventType === 'owner_changed' && event.locationLabel?.trim())
|
||||||
|
.map(key));
|
||||||
|
return events.filter((event) =>
|
||||||
|
event.eventType !== 'location_updated' || !event.locationLabel?.trim() || !ownerLocations.has(key(event)),
|
||||||
|
);
|
||||||
|
};
|
||||||
+85
-41
@@ -216,6 +216,7 @@ textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.side-rail {
|
.side-rail {
|
||||||
|
z-index: 30;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 2rem;
|
top: 2rem;
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -973,33 +974,77 @@ textarea {
|
|||||||
|
|
||||||
.workspace-switcher {
|
.workspace-switcher {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.9rem;
|
gap: 0.45rem;
|
||||||
|
min-width: 0;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
border-bottom: 1px solid rgba(39, 105, 179, 0.16);
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-switcher-item small {
|
.workspace-switcher-label {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-switcher-list {
|
.workspace-switcher { position: relative; }
|
||||||
display: grid;
|
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace-switcher-item {
|
.flock-switcher-trigger {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.7rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 0.8rem;
|
||||||
|
color: var(--ink);
|
||||||
text-align: left;
|
text-align: left;
|
||||||
border: 1px solid rgba(39, 105, 179, 0.12);
|
background: rgba(255, 255, 255, 0.65);
|
||||||
border-radius: 18px;
|
border: 1px solid var(--panel-border);
|
||||||
padding: 0.85rem 0.95rem;
|
border-radius: 16px;
|
||||||
background: rgba(255, 255, 255, 0.58);
|
box-shadow: 0 3px 10px rgba(53, 90, 66, 0.05);
|
||||||
display: grid;
|
|
||||||
gap: 0.2rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-switcher-item.active {
|
.flock-switcher-trigger:hover:not(:disabled) { background: #fffaf0; border-color: var(--accent-green); }
|
||||||
background: linear-gradient(135deg, rgba(203, 58, 53, 0.16), rgba(39, 105, 179, 0.18));
|
.flock-switcher-trigger:focus-visible, .flock-switcher-option:focus-visible { outline: 2px solid var(--accent-green); outline-offset: 3px; }
|
||||||
border-color: rgba(39, 105, 179, 0.24);
|
.flock-switcher-avatar {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: 0 0 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 11px;
|
||||||
|
background: #e1eee2;
|
||||||
|
color: #276b48;
|
||||||
|
font-weight: 800;
|
||||||
}
|
}
|
||||||
|
.flock-switcher-copy { display: grid; gap: 0.15rem; min-width: 0; flex: 1; }
|
||||||
|
.flock-switcher-copy strong { font-size: 0.95rem; line-height: 1.35; overflow-wrap: anywhere; }
|
||||||
|
.flock-switcher-copy small { color: var(--muted); font-size: 0.76rem; font-weight: 400; }
|
||||||
|
.flock-switcher-chevron { flex-shrink: 0; color: var(--muted); }
|
||||||
|
.flock-switcher-chevron.is-open { transform: rotate(180deg); }
|
||||||
|
.flock-switcher-status:empty { display: none; }
|
||||||
|
.flock-switcher-status { color: var(--muted); font-size: 0.78rem; }
|
||||||
|
.flock-switcher-options {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% - 0.5rem);
|
||||||
|
left: 0;
|
||||||
|
z-index: 50;
|
||||||
|
width: max(100%, 280px);
|
||||||
|
max-width: calc(100vw - 3rem);
|
||||||
|
max-height: min(420px, 60dvh);
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0.65rem;
|
||||||
|
border: 1px solid var(--panel-border);
|
||||||
|
border-radius: 18px;
|
||||||
|
background: #fffaf1;
|
||||||
|
box-shadow: 0 18px 45px rgba(35, 65, 45, 0.2);
|
||||||
|
}
|
||||||
|
.flock-switcher-heading { margin: 0; padding: 0.35rem 0.5rem 0.6rem; font-size: 0.9rem; font-weight: 700; }
|
||||||
|
.flock-switcher-group + .flock-switcher-group { border-top: 1px solid var(--panel-border); margin-top: 0.5rem; padding-top: 0.35rem; }
|
||||||
|
.flock-switcher-group > p { margin: 0; padding: 0.4rem 0.5rem; color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
|
||||||
|
.flock-switcher-option { display: flex; align-items: center; gap: 0.7rem; width: 100%; min-height: 54px; padding: 0.65rem; border: 0; border-radius: 11px; background: transparent; color: var(--ink); text-align: left; }
|
||||||
|
.flock-switcher-option:hover, .flock-switcher-option[aria-current="true"] { background: #e8f1e7; }
|
||||||
|
.flock-switcher-check { color: #276b48; font-weight: 800; }
|
||||||
|
|
||||||
.integration-token-secret {
|
.integration-token-secret {
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
@@ -2745,25 +2790,12 @@ label {
|
|||||||
|
|
||||||
.workspace-switcher {
|
.workspace-switcher {
|
||||||
grid-column: 1 / -1;
|
grid-column: 1 / -1;
|
||||||
gap: 0.5rem;
|
gap: 0.4rem;
|
||||||
|
padding-bottom: 0.65rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-switcher-list {
|
|
||||||
display: flex;
|
|
||||||
gap: 0.45rem;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding-bottom: 0.1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace-switcher-item {
|
|
||||||
min-width: 160px;
|
|
||||||
padding: 0.55rem 0.7rem;
|
|
||||||
border-radius: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace-switcher-item small {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 720px) {
|
@media (max-width: 720px) {
|
||||||
@@ -2909,17 +2941,7 @@ label {
|
|||||||
gap: 0.4rem;
|
gap: 0.4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-switcher-list {
|
|
||||||
margin: 0 -0.2rem;
|
|
||||||
padding: 0 0.2rem 0.2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace-switcher-item {
|
|
||||||
min-width: min(180px, 78vw);
|
|
||||||
padding: 0.5rem 0.65rem;
|
|
||||||
border-radius: 999px;
|
|
||||||
font-size: 0.86rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-alert-notification {
|
.top-alert-notification {
|
||||||
gap: 0.65rem;
|
gap: 0.65rem;
|
||||||
@@ -3219,3 +3241,25 @@ label {
|
|||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Memorial profiles stay discoverable while remaining visually subdued. */
|
||||||
|
.bird-card.memorialized {
|
||||||
|
background: #f5f3f0;
|
||||||
|
border-style: dashed;
|
||||||
|
}
|
||||||
|
.bird-card.memorialized .bird-avatar,
|
||||||
|
.memorialized-profile .profile-photo {
|
||||||
|
opacity: 0.6;
|
||||||
|
filter: saturate(0.35);
|
||||||
|
}
|
||||||
|
.bird-card.memorialized .bird-card-copy,
|
||||||
|
.bird-card.memorialized .bird-card-select > strong {
|
||||||
|
opacity: 0.72;
|
||||||
|
}
|
||||||
|
.memorial-label { font-style: italic; }
|
||||||
|
.memorial-banner {
|
||||||
|
padding: 0.85rem 1rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: #f5f3f0;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { test } from 'node:test';
|
||||||
|
import { combineLocationOwnerMarkers } from '../src/birdTimeline.ts';
|
||||||
|
|
||||||
|
const location = { id: 'location', eventType: 'location_updated', eventDate: '2023-04-07', createdAt: '2026-10-07T12:00:00Z', locationLabel: 'Warwick, RI, US', toWorkspaceId: 1 };
|
||||||
|
const owner = { ...location, id: 'owner', eventType: 'owner_changed' };
|
||||||
|
const normalize = (value: string) => value.replace('United States', 'US');
|
||||||
|
|
||||||
|
test('combines a same-date location and owner change without modifying saved events', () => {
|
||||||
|
const events = [location, { ...owner, locationLabel: 'Warwick, RI, United States' }];
|
||||||
|
assert.deepEqual(combineLocationOwnerMarkers(events, normalize).map(event => event.id), ['owner']);
|
||||||
|
assert.equal(events.length, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('preserves different dates, locations, flocks, and standalone location changes', () => {
|
||||||
|
for (const other of [
|
||||||
|
{ ...owner, eventDate: '2023-04-08' },
|
||||||
|
{ ...owner, locationLabel: 'Providence, RI, US' },
|
||||||
|
{ ...owner, toWorkspaceId: 2 },
|
||||||
|
{ ...owner, locationLabel: null },
|
||||||
|
]) assert.equal(combineLocationOwnerMarkers([location, other], normalize).length, 2);
|
||||||
|
assert.deepEqual(combineLocationOwnerMarkers([location], normalize), [location]);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user