Skip to content

Commit

Permalink
feat: Create functionality for budget/count per tag(group)
Browse files Browse the repository at this point in the history
  • Loading branch information
iandebruin98 committed Dec 5, 2024
1 parent fd65a0d commit dec2f36
Show file tree
Hide file tree
Showing 10 changed files with 609 additions and 182 deletions.
28 changes: 14 additions & 14 deletions apps/admin-server/src/pages/projects/[project]/settings/voting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const formSchema = z.object({
'likes',
'count',
'budgeting',
'countPerTheme',
'budgetingPerTheme',
'countPerTag',
'budgetingPerTag',
]).optional(),
minResources: z.coerce.number().gt(-1).optional(),
maxResources: z.coerce.number().gt(-1).optional(),
Expand Down Expand Up @@ -261,10 +261,10 @@ useEffect(() => {
<SelectItem value="likes">Likes</SelectItem>
<SelectItem value="count">Aantallen</SelectItem>
<SelectItem value="budgeting">Begroten</SelectItem>
<SelectItem value="countPerTheme">
<SelectItem value="countPerTag">
Aantal per tag(groep)
</SelectItem>
<SelectItem value="budgetingPerTheme">
<SelectItem value="budgetingPerTag">
Begroten per tag(groep)
</SelectItem>
</SelectContent>
Expand All @@ -273,14 +273,14 @@ useEffect(() => {
</FormItem>
)}
/>
{(fieldValue === 'countPerTheme' || fieldValue === 'count') && (
{(fieldValue === 'countPerTag' || fieldValue === 'count') && (
<FormField
control={form.control}
name="minResources"
render={({ field }) => (
<FormItem className="col-span-1">
<FormLabel>
Wat is de minimum hoeveelheid inzendingen waar iemand op kan stemmen?
Wat is de minimum hoeveelheid inzendingen{form.watch("voteType") === "countPerTag" ? " per tag(groep) " : " "}waar iemand op kan stemmen?
<InfoDialog content={'Dit veld is alleen beschikbaar als één van de volgende types gekozen is: Aantallen, Aantal per tag(groep) of Begroten per tag(groep)'} />
</FormLabel>
<FormControl>
Expand All @@ -291,14 +291,14 @@ useEffect(() => {
)}
/>
)}
{(fieldValue === 'countPerTheme' || fieldValue === 'count') && (
{(fieldValue === 'countPerTag' || fieldValue === 'count') && (
<FormField
control={form.control}
name="maxResources"
render={({ field }) => (
<FormItem className="col-span-1">
<FormLabel>
Wat is de maximum hoeveelheid inzendingen waar iemand op kan stemmen?
Wat is de maximum hoeveelheid inzendingen{form.watch("voteType") === "countPerTag" ? " per tag(groep) " : " "}waar iemand op kan stemmen?
<InfoDialog content={'Dit veld is alleen beschikbaar als één van de volgende types gekozen is: Aantallen, Aantal per tag(groep) of Begroten per tag(groep'} />
</FormLabel>
<FormControl>
Expand All @@ -309,15 +309,15 @@ useEffect(() => {
)}
/>
)}
{(fieldValue === 'budgetingPerTheme' || fieldValue === 'budgeting') && (
{(fieldValue === 'budgetingPerTag' || fieldValue === 'budgeting') && (
<FormField
control={form.control}
name="minBudget"
render={({ field }) => (
<FormItem className="col-span-1">
<FormLabel>
Wat is het minimum budget?
<InfoDialog content={'Dit veld is alleen beschikbaar als één van de volgende types gekozen is: Budgeting '} />
Wat is het minimum budget{form.watch("voteType") === "budgetingPerTag" ? " per tag(groep)" : " "}?
<InfoDialog content={'Dit veld is alleen beschikbaar als één van de volgende types gekozen is: Budgeting, Begroten per tag(groep) '} />
</FormLabel>
<FormControl>
<Input type="number" placeholder="1" {...field} />
Expand All @@ -327,15 +327,15 @@ useEffect(() => {
)}
/>
)}
{(fieldValue === 'budgetingPerTheme' || fieldValue === 'budgeting') && (
{(fieldValue === 'budgetingPerTag' || fieldValue === 'budgeting') && (
<FormField
control={form.control}
name="maxBudget"
render={({ field }) => (
<FormItem className="col-span-1">
<FormLabel>
Wat is het maximum budget?
<InfoDialog content={'Dit veld is alleen beschikbaar als één van de volgende types gekozen is: Budgeting '} />
Wat is het maximum budget{form.watch("voteType") === "budgetingPerTag" ? " per tag(groep)" : " "}?
<InfoDialog content={'Dit veld is alleen beschikbaar als één van de volgende types gekozen is: Budgeting, Begroten per tag(groep) '} />
</FormLabel>
<FormControl>
<Input type="number" placeholder="100" {...field} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export default function BegrootmoduleDisplay(
items={[{ value: 1 }, { value: 2 }, { value: 3 }]}
/>

{ (voteType === 'countPerTheme' || voteType === 'budgetingPerTheme') && (
{ (voteType === 'countPerTag' || voteType === 'budgetingPerTag') && (
<>
<FormField
control={form.control}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function BegrootmoduleExplanation(
step0: props.step0 ?? `<h4>Kies jouw favoriete inzendingen per thema!</h4>
<ol type="1">
<li>Selecteer hieronder een thema om de inzendingen voor dat thema te bekijken</li>
<li>Kies jouw favoriete inzendingen voor dat thema${voteType === 'budgetingPerTheme' ? 'binnen het beschikbare budget' : ''}</li>
<li>Kies jouw favoriete inzendingen voor dat thema${voteType === 'budgetingPerTag' ? 'binnen het beschikbare budget' : ''}</li>
<li>Ga naar het volgende thema om hetzelfde te doen</li>
<li>Klaar en tevreden? In stap 3 vul je ter controle de stemcode in. Tot slot verstuur je in stap 4 je stem</li>
</ol>`,
Expand Down Expand Up @@ -84,7 +84,7 @@ export default function BegrootmoduleExplanation(
onSubmit={form.handleSubmit(onSubmit)}
className="lg:w-1/2 grid grid-cols-1 gap-4">

{ (voteType === 'countPerTheme' || voteType === 'budgetingPerTheme') && (
{ (voteType === 'countPerTag' || voteType === 'budgetingPerTag') && (
<FormField
control={form.control}
name="step0"
Expand Down
2 changes: 1 addition & 1 deletion apps/api-server/src/models/lib/project-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module.exports = {
},
voteType: {
type: 'enum',
values: ['likes', 'count', 'budgeting', 'countPerTheme', 'budgetingPerTheme'],
values: ['likes', 'count', 'budgeting', 'countPerTag', 'budgetingPerTag'],
default: 'likes',
},
voteValues: {
Expand Down
15 changes: 6 additions & 9 deletions apps/api-server/src/routes/api/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ router.route('/*')
if (!( budget >= req.project.config.votes.minBudget && budget <= req.project.config.votes.maxBudget )) {
err = createError(400, 'Budget klopt niet');
}
if (!( req.votes.length >= req.project.config.votes.minResources && req.votes.length <= req.project.config.votes.maxResources )) {
err = createError(400, 'Aantal resources klopt niet');
}
if (err) {
if (transaction) {
return transaction.rollback()
Expand All @@ -357,10 +354,10 @@ router.route('/*')
}
})

// validaties voor voteType=countPerTheme
// validaties voor voteType=countPerTag
.post(function(req, res, next) {
let transaction = res.locals.transaction
if (req.project.config.votes.voteType != 'countPerTheme') return next();
if (req.project.config.votes.voteType != 'countPerTag') return next();
let themes = req.project.config.votes.themes || [];
let totalNoOfVotes = 0;
req.votes.forEach((vote) => {
Expand Down Expand Up @@ -400,10 +397,10 @@ router.route('/*')
}
})

// validaties voor voteType=budgetingPerTheme
// validaties voor voteType=budgetingPerTag
.post(function(req, res, next) {
let transaction = res.locals.transaction
if (req.project.config.votes.voteType != 'budgetingPerTheme') return next();
if (req.project.config.votes.voteType != 'budgetingPerTag') return next();
let themes = req.project.config.votes.themes || [];
req.votes.forEach((vote) => {
let resource = req.resources.find(resource => resource.id == vote.resourceId);
Expand Down Expand Up @@ -458,9 +455,9 @@ router.route('/*')
break;

case 'count':
case 'countPerTheme':
case 'countPerTag':
case 'budgeting':
case 'budgetingPerTheme':
case 'budgetingPerTag':
req.votes.map( vote => actions.push({ action: 'create', vote: vote}) );
req.existingVotes.map( vote => actions.push({ action: 'delete', vote: vote}) );
break;
Expand Down
Loading

0 comments on commit dec2f36

Please sign in to comment.