Skip to content

Commit

Permalink
Fix dates in competitions admin view
Browse files Browse the repository at this point in the history
  • Loading branch information
maxidragon committed Jan 22, 2025
1 parent 92de2b5 commit 55eefa9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/controllers/api/v0/competitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def competition_index
serial_includes = {}

serial_includes["delegates"] = { only: ["id", "name"], methods: [], include: ["avatar"] } if admin_mode
serial_methods |= ["announced_at", "results_submitted_at", "report_posted_at"] if admin_mode
serial_includes["delegate_report"] = { only: ["posted_by_user_id"] } if admin_mode
serial_methods |= ["announced_at", "results_submitted_at", "results_posted_at", "report_posted_at"] if admin_mode

paginate json: competitions,
only: ["id", "name", "start_date", "end_date", "registration_open", "registration_close", "venue"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
isProbablyOver,
PseudoLinkMarkdown,
reportAdminCellContent,
resultsSubmittedAtAdminCellContent,
startYear,
timeDifferenceAfter,
timeDifferenceBefore,
} from '../../lib/utils/competition-table';
import { countries } from '../../lib/wca-data.js.erb';
Expand Down Expand Up @@ -389,11 +389,7 @@ function AdminCompetitionsTable({
warning={resultsPostedStatus === 'warning'}
error={resultsPostedStatus === 'danger'}
>
{
comp.results_posted_at
? timeDifferenceAfter(comp, comp.results_posted_at)
: (isProbablyOver(comp) && I18n.t('competitions.competition_info.pending'))
}
{resultsSubmittedAtAdminCellContent(comp)}
</Table.Cell>
<Table.Cell collapsing>
<Button
Expand Down
13 changes: 12 additions & 1 deletion app/webpacker/lib/utils/competition-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function reportAdminCellContent(comp) {
if (comp.report_posted_at) {
const delegateIds = comp.delegates.map((delegate) => delegate.id);

return delegateIds.includes(comp.report_posted_by_user)
return delegateIds.includes(comp.delegate_report.posted_by_user_id)
? timeDifferenceAfter(comp, comp.report_posted_at)
: I18n.t('competitions.competition_info.submitted_by_other');
}
Expand All @@ -118,6 +118,17 @@ export function reportAdminCellContent(comp) {
return null;
}

export function resultsSubmittedAtAdminCellContent(comp) {
if (comp.results_posted_at) {
const date = comp.results_submitted_at ? comp.results_submitted_at : comp.results_posted_at;
return timeDifferenceAfter(comp, date);
}
if ((isProbablyOver(comp))) {
I18n.t('competitions.competition_info.pending');
}
return null;
}

function lookupStatus(numOfDays, statusMap, compareFn, defaultStatus = null) {
if (!Number.isInteger(numOfDays)) {
return defaultStatus;
Expand Down

0 comments on commit 55eefa9

Please sign in to comment.