Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc07026a88 | ||
|
|
ff177dbaed | ||
|
|
0e2aa9366f | ||
|
|
270652f1a8 | ||
|
|
56d8818581 | ||
|
|
f676b94e36 | ||
|
|
cf8dceb014 | ||
|
|
ac4b50293e | ||
|
|
802544e452 | ||
|
|
8205fee420 | ||
|
|
4869756957 |
No files matched your search
@@ -37,12 +37,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
|
||||||
@@ -53,7 +57,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||||
JOB_STATUS: ${{ job.status }}
|
JOB_STATUS: ${{ job.status }}
|
||||||
DEPLOY_ENVIRONMENT: dev
|
|
||||||
run: |
|
run: |
|
||||||
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
|
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
|
||||||
echo "DISCORD_WEBHOOK_URL is not configured; skipping Discord notification."
|
echo "DISCORD_WEBHOOK_URL is not configured; skipping Discord notification."
|
||||||
@@ -61,14 +64,53 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$JOB_STATUS" = "success" ]; then
|
if [ "$JOB_STATUS" = "success" ]; then
|
||||||
STATUS_LABEL="SUCCESS"
|
STATUS_TITLE="Deploy succeeded"
|
||||||
|
COLOR=65280
|
||||||
else
|
else
|
||||||
STATUS_LABEL="FAILED"
|
STATUS_TITLE="Deploy failed"
|
||||||
|
COLOR=16711680
|
||||||
fi
|
fi
|
||||||
|
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||||
|
AVATAR_URL="${{ vars.DISCORD_AVATAR_URL }}"
|
||||||
|
AVATAR_URL="${AVATAR_URL:-https://www.flockpal.app/FlockPal-Paint.png}"
|
||||||
|
COMMIT_MESSAGE="$(git -C /docker/FlockPal-dev log -1 --pretty=%s 2>/dev/null || printf '%s' '${{ github.sha }}')"
|
||||||
|
json_escape() {
|
||||||
|
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||||
|
}
|
||||||
|
BRANCH="$(json_escape '${{ github.ref_name }}')"
|
||||||
|
MESSAGE="$(json_escape "$COMMIT_MESSAGE")"
|
||||||
|
AVATAR_URL="$(json_escape "$AVATAR_URL")"
|
||||||
|
|
||||||
|
cat > /tmp/discord-payload.json <<EOF
|
||||||
|
{
|
||||||
|
"username": "FlockPal Build",
|
||||||
|
"avatar_url": "${AVATAR_URL}",
|
||||||
|
"embeds": [
|
||||||
|
{
|
||||||
|
"title": "${STATUS_TITLE}",
|
||||||
|
"url": "${RUN_URL}",
|
||||||
|
"description": "FlockPal dev deploy",
|
||||||
|
"color": ${COLOR},
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Branch",
|
||||||
|
"value": "${BRANCH}",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Message",
|
||||||
|
"value": "${MESSAGE}",
|
||||||
|
"inline": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
curl --fail --show-error --silent \
|
curl --fail --show-error --silent \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"content\":\"[${STATUS_LABEL}] FlockPal ${DEPLOY_ENVIRONMENT} deploy completed with status: ${JOB_STATUS}\\nBranch: ${{ github.ref_name }}\\nCommit: ${{ github.sha }}\\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
|
-d @/tmp/discord-payload.json \
|
||||||
"$DISCORD_WEBHOOK_URL" || echo "Discord notification failed."
|
"$DISCORD_WEBHOOK_URL" || echo "Discord notification failed."
|
||||||
|
|
||||||
deploy-prod:
|
deploy-prod:
|
||||||
@@ -99,12 +141,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
|
||||||
@@ -121,7 +167,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||||
JOB_STATUS: ${{ job.status }}
|
JOB_STATUS: ${{ job.status }}
|
||||||
DEPLOY_ENVIRONMENT: production
|
|
||||||
run: |
|
run: |
|
||||||
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
|
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
|
||||||
echo "DISCORD_WEBHOOK_URL is not configured; skipping Discord notification."
|
echo "DISCORD_WEBHOOK_URL is not configured; skipping Discord notification."
|
||||||
@@ -129,12 +174,51 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$JOB_STATUS" = "success" ]; then
|
if [ "$JOB_STATUS" = "success" ]; then
|
||||||
STATUS_LABEL="SUCCESS"
|
STATUS_TITLE="Deploy succeeded"
|
||||||
|
COLOR=65280
|
||||||
else
|
else
|
||||||
STATUS_LABEL="FAILED"
|
STATUS_TITLE="Deploy failed"
|
||||||
|
COLOR=16711680
|
||||||
fi
|
fi
|
||||||
|
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||||
|
AVATAR_URL="${{ vars.DISCORD_AVATAR_URL }}"
|
||||||
|
AVATAR_URL="${AVATAR_URL:-https://www.flockpal.app/FlockPal-Paint.png}"
|
||||||
|
COMMIT_MESSAGE="$(git -C /docker/FlockPal log -1 --pretty=%s 2>/dev/null || printf '%s' '${{ github.sha }}')"
|
||||||
|
json_escape() {
|
||||||
|
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||||
|
}
|
||||||
|
BRANCH="$(json_escape '${{ github.ref_name }}')"
|
||||||
|
MESSAGE="$(json_escape "$COMMIT_MESSAGE")"
|
||||||
|
AVATAR_URL="$(json_escape "$AVATAR_URL")"
|
||||||
|
|
||||||
|
cat > /tmp/discord-payload.json <<EOF
|
||||||
|
{
|
||||||
|
"username": "FlockPal Build",
|
||||||
|
"avatar_url": "${AVATAR_URL}",
|
||||||
|
"embeds": [
|
||||||
|
{
|
||||||
|
"title": "${STATUS_TITLE}",
|
||||||
|
"url": "${RUN_URL}",
|
||||||
|
"description": "FlockPal production deploy",
|
||||||
|
"color": ${COLOR},
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Branch",
|
||||||
|
"value": "${BRANCH}",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Message",
|
||||||
|
"value": "${MESSAGE}",
|
||||||
|
"inline": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
curl --fail --show-error --silent \
|
curl --fail --show-error --silent \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"content\":\"[${STATUS_LABEL}] FlockPal ${DEPLOY_ENVIRONMENT} deploy completed with status: ${JOB_STATUS}\\nBranch: ${{ github.ref_name }}\\nCommit: ${{ github.sha }}\\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
|
-d @/tmp/discord-payload.json \
|
||||||
"$DISCORD_WEBHOOK_URL" || echo "Discord notification failed."
|
"$DISCORD_WEBHOOK_URL" || echo "Discord notification failed."
|
||||||
@@ -103,7 +103,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`
|
||||||
|
|||||||
+3
-5
@@ -657,7 +657,6 @@ const normalizeBird = (row: BirdRow) => ({
|
|||||||
publicProfileEnabled: row.public_profile_enabled ?? false,
|
publicProfileEnabled: row.public_profile_enabled ?? false,
|
||||||
memorializedAt: row.memorialized_at,
|
memorializedAt: row.memorialized_at,
|
||||||
memorializedOn: row.memorialized_on,
|
memorializedOn: row.memorialized_on,
|
||||||
memorialNote: row.memorial_note,
|
|
||||||
notifyOnMemorialDay: row.notify_on_memorial_day,
|
notifyOnMemorialDay: row.notify_on_memorial_day,
|
||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
latestWeightGrams: row.latest_weight_grams ? Number(row.latest_weight_grams) : null,
|
latestWeightGrams: row.latest_weight_grams ? Number(row.latest_weight_grams) : null,
|
||||||
@@ -1712,9 +1711,7 @@ const buildBirdMilestoneReminderCopy = (reminder: BirdMilestoneReminderCandidate
|
|||||||
yearCount > 0
|
yearCount > 0
|
||||||
? `From our flock to yours, holding ${reminder.name}'s memory close on this ${formatOrdinal(yearCount)} memorial day.`
|
? `From our flock to yours, holding ${reminder.name}'s memory close on this ${formatOrdinal(yearCount)} memorial day.`
|
||||||
: `From our flock to yours, holding ${reminder.name}'s memory close today.`,
|
: `From our flock to yours, holding ${reminder.name}'s memory close today.`,
|
||||||
body: reminder.memorial_note
|
body: 'A quiet moment for the feathers, songs, routines, and happy memories that still stay with you.',
|
||||||
? reminder.memorial_note
|
|
||||||
: 'A quiet moment for the feathers, songs, routines, and happy memories that still stay with you.',
|
|
||||||
milestoneLabel: yearCount > 0 ? `${formatOrdinal(yearCount)} Memorial Day` : 'Memorial Day on file',
|
milestoneLabel: yearCount > 0 ? `${formatOrdinal(yearCount)} Memorial Day` : 'Memorial Day on file',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -3569,6 +3566,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!) });
|
||||||
@@ -3948,6 +3946,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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -4015,7 +4014,6 @@ app.post('/api/birds/:birdId/memorialize', requireAuth, requireWriteAccess, requ
|
|||||||
birdId: req.params.birdId,
|
birdId: req.params.birdId,
|
||||||
workspaceId: req.auth!.workspace.id,
|
workspaceId: req.auth!.workspace.id,
|
||||||
memorializedOn: parsed.data.memorializedOn,
|
memorializedOn: parsed.data.memorializedOn,
|
||||||
memorialNote: emptyToNull(parsed.data.memorialNote),
|
|
||||||
notifyOnMemorialDay: parsed.data.notifyOnMemorialDay ?? false,
|
notifyOnMemorialDay: parsed.data.notifyOnMemorialDay ?? false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,6 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
|
|||||||
public_profile_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
public_profile_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
memorialized_at TIMESTAMPTZ,
|
memorialized_at TIMESTAMPTZ,
|
||||||
memorialized_on DATE,
|
memorialized_on DATE,
|
||||||
memorial_note VARCHAR(1000),
|
|
||||||
notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE,
|
notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
@@ -265,7 +264,6 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
|
|||||||
ADD COLUMN IF NOT EXISTS public_profile_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
ADD COLUMN IF NOT EXISTS public_profile_enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
ADD COLUMN IF NOT EXISTS memorialized_at TIMESTAMPTZ,
|
ADD COLUMN IF NOT EXISTS memorialized_at TIMESTAMPTZ,
|
||||||
ADD COLUMN IF NOT EXISTS memorialized_on DATE,
|
ADD COLUMN IF NOT EXISTS memorialized_on DATE,
|
||||||
ADD COLUMN IF NOT EXISTS memorial_note VARCHAR(1000),
|
|
||||||
ADD COLUMN IF NOT EXISTS notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE;
|
ADD COLUMN IF NOT EXISTS notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
|
||||||
ALTER TABLE birds
|
ALTER TABLE birds
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const birdResponse = z.object({
|
|||||||
photoDataUrl: text.describe('Photo URL or legacy data URL. Storage-backed URLs expire; refresh the bird list to obtain a new URL.'),
|
photoDataUrl: text.describe('Photo URL or legacy data URL. Storage-backed URLs expire; refresh the bird list to obtain a new URL.'),
|
||||||
photoObjectKey: text, photoContentType: text, photoUpdatedAt: timestamp.nullable(),
|
photoObjectKey: text, photoContentType: text, photoUpdatedAt: timestamp.nullable(),
|
||||||
notifyOnDob: z.boolean(), notifyOnGotchaDay: z.boolean(), publicProfileCode: text, publicProfileEnabled: z.boolean(),
|
notifyOnDob: z.boolean(), notifyOnGotchaDay: z.boolean(), publicProfileCode: text, publicProfileEnabled: z.boolean(),
|
||||||
memorializedAt: timestamp.nullable(), memorializedOn: date.nullable(), memorialNote: text,
|
memorializedAt: timestamp.nullable(), memorializedOn: date.nullable(),
|
||||||
notifyOnMemorialDay: z.boolean(), createdAt: timestamp,
|
notifyOnMemorialDay: z.boolean(), createdAt: timestamp,
|
||||||
latestWeightGrams: z.number().nullable(), latestRecordedOn: date.nullable(),
|
latestWeightGrams: z.number().nullable(), latestRecordedOn: date.nullable(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ const birdSelectFields = `
|
|||||||
birds.public_profile_enabled,
|
birds.public_profile_enabled,
|
||||||
birds.memorialized_at,
|
birds.memorialized_at,
|
||||||
birds.memorialized_on::text,
|
birds.memorialized_on::text,
|
||||||
birds.memorial_note,
|
|
||||||
birds.notify_on_memorial_day,
|
birds.notify_on_memorial_day,
|
||||||
birds.created_at,
|
birds.created_at,
|
||||||
latest.weight_grams AS latest_weight_grams,
|
latest.weight_grams AS latest_weight_grams,
|
||||||
@@ -544,7 +543,7 @@ export const createBird = async ({
|
|||||||
const result = await db.query<BirdRow>(
|
const result = await db.query<BirdRow>(
|
||||||
`INSERT INTO birds (id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth, gotcha_day, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled)
|
`INSERT INTO birds (id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth, gotcha_day, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled)
|
||||||
VALUES (COALESCE($1::uuid, gen_random_uuid()), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
|
VALUES (COALESCE($1::uuid, gen_random_uuid()), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
|
||||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at, NULL::text AS latest_weight_grams, NULL::text AS latest_recorded_on`,
|
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at, NULL::text AS latest_weight_grams, NULL::text AS latest_recorded_on`,
|
||||||
[
|
[
|
||||||
birdId ?? null,
|
birdId ?? null,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
@@ -662,7 +661,7 @@ export const updateBird = async ({
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
AND workspace_id = $26
|
AND workspace_id = $26
|
||||||
AND memorialized_at IS NULL
|
AND memorialized_at IS NULL
|
||||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||||
(
|
(
|
||||||
SELECT weight_grams::text
|
SELECT weight_grams::text
|
||||||
FROM weight_records
|
FROM weight_records
|
||||||
@@ -714,25 +713,22 @@ export const memorializeBird = async ({
|
|||||||
birdId,
|
birdId,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
memorializedOn,
|
memorializedOn,
|
||||||
memorialNote,
|
|
||||||
notifyOnMemorialDay,
|
notifyOnMemorialDay,
|
||||||
}: {
|
}: {
|
||||||
birdId: string;
|
birdId: string;
|
||||||
workspaceId: number;
|
workspaceId: number;
|
||||||
memorializedOn: string;
|
memorializedOn: string;
|
||||||
memorialNote: string | null;
|
|
||||||
notifyOnMemorialDay: boolean;
|
notifyOnMemorialDay: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const result = await db.query<BirdRow>(
|
const result = await db.query<BirdRow>(
|
||||||
`UPDATE birds
|
`UPDATE birds
|
||||||
SET memorialized_at = CURRENT_TIMESTAMP,
|
SET memorialized_at = CURRENT_TIMESTAMP,
|
||||||
memorialized_on = $3,
|
memorialized_on = $3,
|
||||||
memorial_note = $4,
|
notify_on_memorial_day = $4
|
||||||
notify_on_memorial_day = $5
|
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
AND workspace_id = $2
|
AND workspace_id = $2
|
||||||
AND memorialized_at IS NULL
|
AND memorialized_at IS NULL
|
||||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||||
(
|
(
|
||||||
SELECT weight_grams::text
|
SELECT weight_grams::text
|
||||||
FROM weight_records
|
FROM weight_records
|
||||||
@@ -747,7 +743,7 @@ export const memorializeBird = async ({
|
|||||||
ORDER BY recorded_on DESC
|
ORDER BY recorded_on DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
) AS latest_recorded_on`,
|
) AS latest_recorded_on`,
|
||||||
[birdId, workspaceId, memorializedOn, memorialNote, notifyOnMemorialDay],
|
[birdId, workspaceId, memorializedOn, notifyOnMemorialDay],
|
||||||
);
|
);
|
||||||
|
|
||||||
return result.rows[0] ?? null;
|
return result.rows[0] ?? null;
|
||||||
@@ -768,7 +764,7 @@ export const updateMemorialReminderPreference = async ({
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
AND workspace_id = $2
|
AND workspace_id = $2
|
||||||
AND memorialized_at IS NOT NULL
|
AND memorialized_at IS NOT NULL
|
||||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||||
(
|
(
|
||||||
SELECT weight_grams::text
|
SELECT weight_grams::text
|
||||||
FROM weight_records
|
FROM weight_records
|
||||||
@@ -796,7 +792,7 @@ export const transferBirdToWorkspace = async (birdId: string, sourceWorkspaceId:
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
AND workspace_id = $2
|
AND workspace_id = $2
|
||||||
AND memorialized_at IS NULL
|
AND memorialized_at IS NULL
|
||||||
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
|
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, location_label, location_details, vet_clinic_name, vet_clinic_address, vet_account_number, vet_doctor_name, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, notify_on_memorial_day, created_at,
|
||||||
(
|
(
|
||||||
SELECT weight_grams::text
|
SELECT weight_grams::text
|
||||||
FROM weight_records
|
FROM weight_records
|
||||||
|
|||||||
@@ -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),
|
||||||
@@ -129,7 +130,6 @@ export const birdSchema = z.object({
|
|||||||
|
|
||||||
export const memorializeBirdSchema = z.object({
|
export const memorializeBirdSchema = z.object({
|
||||||
memorializedOn: dateStringSchema,
|
memorializedOn: dateStringSchema,
|
||||||
memorialNote: z.string().trim().max(1000).optional().or(z.literal('')),
|
|
||||||
notifyOnMemorialDay: z.boolean().optional(),
|
notifyOnMemorialDay: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ export type BirdRow = {
|
|||||||
public_profile_enabled: boolean;
|
public_profile_enabled: boolean;
|
||||||
memorialized_at: string | null;
|
memorialized_at: string | null;
|
||||||
memorialized_on: string | null;
|
memorialized_on: string | null;
|
||||||
memorial_note: string | null;
|
|
||||||
notify_on_memorial_day: boolean;
|
notify_on_memorial_day: boolean;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
latest_weight_grams: string | null;
|
latest_weight_grams: string | null;
|
||||||
|
|||||||
+88
-82
@@ -1,3 +1,4 @@
|
|||||||
|
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';
|
||||||
@@ -65,7 +66,6 @@ type Bird = {
|
|||||||
publicProfileEnabled: boolean;
|
publicProfileEnabled: boolean;
|
||||||
memorializedAt: string | null;
|
memorializedAt: string | null;
|
||||||
memorializedOn: string | null;
|
memorializedOn: string | null;
|
||||||
memorialNote: string | null;
|
|
||||||
notifyOnMemorialDay: boolean;
|
notifyOnMemorialDay: boolean;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
latestWeightGrams: number | null;
|
latestWeightGrams: number | null;
|
||||||
@@ -272,6 +272,7 @@ type FlockNoteFormState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type BirdFormState = {
|
type BirdFormState = {
|
||||||
|
locationDate: string;
|
||||||
name: string;
|
name: string;
|
||||||
tagId: string;
|
tagId: string;
|
||||||
species: string;
|
species: string;
|
||||||
@@ -335,7 +336,6 @@ type PublicBirdProfile = {
|
|||||||
|
|
||||||
type MemorializeBirdFormState = {
|
type MemorializeBirdFormState = {
|
||||||
memorializedOn: string;
|
memorializedOn: string;
|
||||||
memorialNote: string;
|
|
||||||
notifyOnMemorialDay: boolean;
|
notifyOnMemorialDay: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -814,6 +814,7 @@ const VerifiedLocationSearchField = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const emptyBirdForm: BirdFormState = {
|
const emptyBirdForm: BirdFormState = {
|
||||||
|
locationDate: '',
|
||||||
name: '',
|
name: '',
|
||||||
tagId: '',
|
tagId: '',
|
||||||
species: '',
|
species: '',
|
||||||
@@ -856,7 +857,6 @@ const emptyVeterinaryInfoForm: VeterinaryInfoFormState = {
|
|||||||
|
|
||||||
const emptyMemorializeBirdForm = (): MemorializeBirdFormState => ({
|
const emptyMemorializeBirdForm = (): MemorializeBirdFormState => ({
|
||||||
memorializedOn: new Date().toISOString().slice(0, 10),
|
memorializedOn: new Date().toISOString().slice(0, 10),
|
||||||
memorialNote: '',
|
|
||||||
notifyOnMemorialDay: false,
|
notifyOnMemorialDay: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -969,6 +969,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,
|
||||||
@@ -1146,7 +1147,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') {
|
||||||
@@ -1169,7 +1170,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') {
|
||||||
@@ -1191,7 +1192,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 '';
|
||||||
@@ -1246,7 +1247,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') {
|
||||||
@@ -1346,7 +1347,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) => ({
|
||||||
@@ -2262,9 +2263,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 &&
|
||||||
@@ -2981,7 +2983,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)) ?? {};
|
||||||
@@ -3679,6 +3681,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);
|
||||||
@@ -3991,7 +3994,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) {
|
||||||
@@ -4659,7 +4662,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) {
|
||||||
@@ -4688,17 +4691,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];
|
||||||
@@ -6363,7 +6363,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);
|
||||||
@@ -6371,7 +6371,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">
|
||||||
@@ -6388,11 +6388,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>
|
||||||
|
{!bird.memorializedAt || bird.latestWeightGrams !== null ? (
|
||||||
<strong>{formatWeight(bird.latestWeightGrams)}</strong>
|
<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">
|
||||||
@@ -6589,27 +6592,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">
|
||||||
@@ -6748,6 +6730,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">
|
||||||
@@ -6996,14 +7009,6 @@ function App() {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label className="wide-field">
|
|
||||||
Memorial note
|
|
||||||
<textarea
|
|
||||||
rows={3}
|
|
||||||
value={memorializeBirdForm.memorialNote}
|
|
||||||
onChange={(event) => setMemorializeBirdForm({ ...memorializeBirdForm, memorialNote: event.target.value })}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<div className="button-row care-form-actions">
|
<div className="button-row care-form-actions">
|
||||||
<button className="danger-button" type="submit" disabled={memorializingBird || activeMembership?.role !== 'owner'}>
|
<button className="danger-button" type="submit" disabled={memorializingBird || activeMembership?.role !== 'owner'}>
|
||||||
{memorializingBird ? 'Memorializing...' : `Memorialize ${selectedBird.name}`}
|
{memorializingBird ? 'Memorializing...' : `Memorialize ${selectedBird.name}`}
|
||||||
@@ -7124,7 +7129,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">
|
||||||
@@ -7177,7 +7182,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 ? (
|
||||||
@@ -7187,7 +7192,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" />
|
||||||
@@ -7214,6 +7219,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{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">
|
<div className="bird-detail-tab-panel">
|
||||||
{selectedBirdTab === 'info' ? (
|
{selectedBirdTab === 'info' ? (
|
||||||
<div className="flock-member-sections" role="tabpanel">
|
<div className="flock-member-sections" role="tabpanel">
|
||||||
@@ -7264,7 +7270,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>
|
||||||
@@ -7431,7 +7437,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
|
||||||
@@ -7462,16 +7468,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) => (
|
||||||
@@ -7480,7 +7486,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>
|
||||||
@@ -7507,7 +7513,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"
|
||||||
>
|
>
|
||||||
@@ -7519,7 +7525,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
|
||||||
@@ -7555,7 +7561,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
|
||||||
@@ -7565,7 +7571,7 @@ function App() {
|
|||||||
setEditingVeterinaryInfo(false);
|
setEditingVeterinaryInfo(false);
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={savingVeterinaryInfo}
|
disabled={Boolean(selectedBird.memorializedAt) || (savingVeterinaryInfo)}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
@@ -7601,7 +7607,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
|
||||||
@@ -7637,16 +7643,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 ? (
|
||||||
@@ -7658,7 +7664,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 ? (
|
||||||
@@ -7666,7 +7672,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>
|
||||||
@@ -7695,7 +7701,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
|
||||||
@@ -7706,10 +7712,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) => (
|
||||||
@@ -7724,7 +7730,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>
|
||||||
@@ -7762,10 +7768,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>
|
||||||
@@ -7849,7 +7855,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
|
||||||
@@ -7870,7 +7876,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>
|
||||||
@@ -7920,8 +7926,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}
|
||||||
@@ -7938,7 +7944,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 ? (
|
||||||
@@ -7946,7 +7952,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) => (
|
||||||
@@ -7965,7 +7971,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>
|
||||||
|
|||||||
@@ -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)),
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -3096,3 +3096,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