Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend admin frontend with duplication, copying, and progress operations #215

Merged
merged 14 commits into from
May 1, 2024
56 changes: 56 additions & 0 deletions admin/src/components/Achievements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function AchiemementCard(props: {
onSelect: () => void;
onEdit: () => void;
onDelete: () => void;
onCopy: () => void;
}) {
return (
<>
Expand Down Expand Up @@ -80,6 +81,9 @@ function AchiemementCard(props: {
<HButton onClick={props.onEdit} float="right">
EDIT
</HButton>
<HButton onClick={props.onCopy} float="right">
COPY
</HButton>
</ListCardButtons>
</ListCardBox>
</>
Expand Down Expand Up @@ -146,13 +150,30 @@ function toForm(achievement: AchievementDto) {
] as EntryForm[];
}

function makeCopyForm(orgOptions: string[], initialIndex: number) {
return [
{
name: "Target Organization",
options: orgOptions,
value: initialIndex,
},
] as EntryForm[];
}

export function Achievements() {
const serverData = useContext(ServerDataContext);
const [isCreateModalOpen, setCreateModalOpen] = useState(false);
const [isEditModalOpen, setEditModalOpen] = useState(false);
const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);
const [selectModalOpen, setSelectModalOpen] = useState(false);
const [isLinkedModalOpen, setLinkedModalOpen] = useState(false);

const [isCopyModalOpen, setCopyModalOpen] = useState(false);
const [copyForm, setCopyForm] = useState(() => ({
form: makeCopyForm([], 0),
orgIds: [] as string[],
}));

const [form, setForm] = useState(() => makeForm());
const [currentId, setCurrentId] = useState("");
const [query, setQuery] = useState("");
Expand Down Expand Up @@ -203,6 +224,26 @@ export function Achievements() {
}}
form={form}
/>
<EntryModal
title="Copy Achievement"
isOpen={isCopyModalOpen}
entryButtonText="COPY"
onEntry={async () => {
const ach = serverData.achievements.get(currentId)!;
serverData.updateAchievement({
...ach,
eventId: "",
initialOrganizationId:
copyForm.orgIds[(copyForm.form[0] as OptionEntryForm).value],
id: "",
});
setCopyModalOpen(false);
}}
onCancel={() => {
setCopyModalOpen(false);
}}
form={copyForm.form}
/>
<DeleteModal
objectName={serverData.achievements.get(currentId)?.name ?? ""}
isOpen={isDeleteModalOpen}
Expand Down Expand Up @@ -280,6 +321,21 @@ export function Achievements() {
setForm(toForm(ach));
setEditModalOpen(true);
}}
onCopy={() => {
const orgs = Array.from(serverData.organizations.values());
const myOrgIndex = orgs.findIndex(
(v) => v.id === selectedOrg?.id
);
setCurrentId(ach.id);
setCopyForm({
form: makeCopyForm(
orgs.map((org) => org.name ?? ""),
myOrgIndex
),
orgIds: orgs.map((org) => org.id),
});
setCopyModalOpen(true);
}}
/>
))}
</>
Expand Down
54 changes: 54 additions & 0 deletions admin/src/components/Challenges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function ChallengeCard(props: {
onDown: () => void;
onDelete: () => void;
onEdit: () => void;
onCopy: () => void;
}) {
return (
<ListCardBox>
Expand All @@ -79,6 +80,9 @@ function ChallengeCard(props: {
<HButton onClick={props.onEdit} float="right">
EDIT
</HButton>
<HButton onClick={props.onCopy} float="right">
COPY
</HButton>
</ListCardButtons>
</ListCardBox>
);
Expand Down Expand Up @@ -170,6 +174,16 @@ function fromForm(
};
}

function makeCopyForm(evOptions: string[], initialIndex: number) {
return [
{
name: "Target Event",
options: evOptions,
value: initialIndex,
},
] as EntryForm[];
}

export function Challenges() {
const [createModalOpen, setCreateModalOpen] = useState(false);
const [editModalOpen, setEditModalOpen] = useState(false);
Expand All @@ -180,6 +194,12 @@ export function Challenges() {
const [currentId, setCurrentId] = useState("");
const [query, setQuery] = useState("");

const [isCopyModalOpen, setCopyModalOpen] = useState(false);
const [copyForm, setCopyForm] = useState(() => ({
form: makeCopyForm([], 0),
evIds: [] as string[],
}));

const serverData = useContext(ServerDataContext);
const selectedEvent = serverData.events.get(serverData.selectedEvent);

Expand Down Expand Up @@ -229,6 +249,25 @@ export function Challenges() {
setDeleteModalOpen(false);
}}
/>
<EntryModal
title="Copy Challenge"
isOpen={isCopyModalOpen}
entryButtonText="COPY"
onEntry={async () => {
const chal = serverData.challenges.get(currentId)!;
serverData.updateChallenge({
...chal,
linkedEventId:
copyForm.evIds[(copyForm.form[0] as OptionEntryForm).value],
id: "",
});
setCopyModalOpen(false);
}}
onCancel={() => {
setCopyModalOpen(false);
}}
form={copyForm.form}
/>
<SearchBar
onCreate={() => {
setForm(makeForm());
Expand Down Expand Up @@ -292,6 +331,21 @@ export function Challenges() {
setCurrentId(chal.id);
setDeleteModalOpen(true);
}}
onCopy={() => {
const evs = Array.from(serverData.events.values());
const myEvIndex = evs.findIndex(
(v) => v.id === selectedEvent?.id
);
setCurrentId(chal.id);
setCopyForm({
form: makeCopyForm(
evs.map((ev) => ev.name ?? ""),
myEvIndex
),
evIds: evs.map((ev) => ev.id),
});
setCopyModalOpen(true);
}}
/>
))}
</>
Expand Down
68 changes: 68 additions & 0 deletions admin/src/components/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function EventCard(props: {
onSelect: () => void;
onEdit: () => void;
onDelete: () => void;
onCopy: () => void;
}) {
const requiredText =
props.event.requiredMembers && props.event.requiredMembers < 0
Expand Down Expand Up @@ -99,6 +100,9 @@ function EventCard(props: {
<HButton onClick={props.onEdit} float="right">
EDIT
</HButton>
<HButton onClick={props.onCopy} float="right">
COPY
</HButton>
</ListCardButtons>
</ListCardBox>
</>
Expand Down Expand Up @@ -201,12 +205,29 @@ function toForm(event: EventDto) {
] as EntryForm[];
}

function makeCopyForm(orgOptions: string[], initialIndex: number) {
return [
{
name: "Target Organization",
options: orgOptions,
value: initialIndex,
},
] as EntryForm[];
}

export function Events() {
const serverData = useContext(ServerDataContext);
const [isCreateModalOpen, setCreateModalOpen] = useState(false);
const [isEditModalOpen, setEditModalOpen] = useState(false);
const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);
const [selectModalOpen, setSelectModalOpen] = useState(false);

const [isCopyModalOpen, setCopyModalOpen] = useState(false);
const [copyForm, setCopyForm] = useState(() => ({
form: makeCopyForm([], 0),
orgIds: [] as string[],
}));

const [form, setForm] = useState(() => makeForm());
const [currentId, setCurrentId] = useState("");
const [query, setQuery] = useState("");
Expand Down Expand Up @@ -252,6 +273,38 @@ export function Events() {
}}
form={form}
/>
<EntryModal
title="Copy Event"
isOpen={isCopyModalOpen}
entryButtonText="COPY"
onEntry={async () => {
const ev = serverData.events.get(currentId)!;
const evId = await serverData.updateEvent({
...ev,
challenges: [],
initialOrganizationId:
copyForm.orgIds[(copyForm.form[0] as OptionEntryForm).value],
id: "",
});
if (!evId) {
setCopyModalOpen(false);
return;
}
for (const chalId of ev.challenges!) {
const chal = serverData.challenges.get(chalId)!;
serverData.updateChallenge({
...chal,
linkedEventId: evId,
id: "",
});
}
setCopyModalOpen(false);
}}
onCancel={() => {
setCopyModalOpen(false);
}}
form={copyForm.form}
/>
<DeleteModal
objectName={serverData.events.get(currentId)?.name ?? ""}
isOpen={isDeleteModalOpen}
Expand Down Expand Up @@ -307,6 +360,21 @@ export function Events() {
setForm(toForm(ev));
setEditModalOpen(true);
}}
onCopy={() => {
const orgs = Array.from(serverData.organizations.values());
const myOrgIndex = orgs.findIndex(
(v) => v.id === selectedOrg?.id
);
setCurrentId(ev.id);
setCopyForm({
form: makeCopyForm(
orgs.map((org) => org.name ?? ""),
myOrgIndex
),
orgIds: orgs.map((org) => org.id),
});
setCopyModalOpen(true);
}}
/>
))}
</>
Expand Down
Loading
Loading