Skip to content

Commit

Permalink
add setting to groups page too
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey committed Nov 28, 2023
1 parent 6731a67 commit 3c63dd8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/wishlists/ItemCard/ClaimButtons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{:else if showName}
<span>Claimed by {item.pledgedBy?.name}</span>
{:else}
<button class="variant-filled-secondary btn btn-sm md:btn" disabled>Claimed</button>
<span>Claimed</span>
{/if}
{:else}
<button class="variant-filled-secondary btn btn-sm md:btn" on:click={() => dispatch("claim")}>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export enum ConfigKey {
CLAIMS_SHOW_NAME = "claims.showName"
}

type GroupConfig = Partial<Pick<Config, "suggestions">>;
type GroupConfig = Partial<Pick<Config, "suggestions" | "claims">>;

export const getConfig = async (groupId?: string): Promise<Config> => {
let configItems = await client.systemConfig.findMany({
Expand Down Expand Up @@ -72,7 +72,8 @@ export const getConfig = async (groupId?: string): Promise<Config> => {
},
smtp: smtpConfig,
claims: {
showName: configMap[ConfigKey.CLAIMS_SHOW_NAME] === "true"
showName: configMap[ConfigKey.CLAIMS_SHOW_NAME] === "true",
...groupConfig.claims
}
};

Expand All @@ -96,6 +97,9 @@ const getGroupConfig = async (groupId: string): Promise<GroupConfig> => {
suggestions: {
enable: configMap[ConfigKey.SUGGESTIONS_ENABLE] === "true",
method: (configMap[ConfigKey.SUGGESTIONS_METHOD] as SuggestionMethod) || "approval"
},
claims: {
showName: configMap[ConfigKey.CLAIMS_SHOW_NAME] === "true"
}
};
}
Expand Down
6 changes: 5 additions & 1 deletion src/routes/admin/groups/[groupId]/settings/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const actions: Actions = {
const formData = Object.fromEntries(await request.formData());
const groupSettingSchema = settingSchema.pick({
suggestionMethod: true,
enableSuggestions: true
enableSuggestions: true,
claimsShowName: true
});

const configData = groupSettingSchema.safeParse(formData);
Expand All @@ -63,6 +64,9 @@ export const actions: Actions = {
suggestions: {
enable: configData.data.enableSuggestions,
method: configData.data.suggestionMethod
},
claims: {
showName: configData.data.claimsShowName
}
};
await writeConfig(newConfig, params.groupId);
Expand Down
16 changes: 12 additions & 4 deletions src/routes/admin/groups/[groupId]/settings/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { enhance } from "$app/forms";
import Claims from "$lib/components/admin/SettingsForm/Claims.svelte";
import Suggestions from "$lib/components/admin/SettingsForm/Suggestions.svelte";
import type { PageData } from "./$types";
Expand All @@ -18,10 +19,17 @@
};
}}
>
<Suggestions
bind:enabled={data.config.suggestions.enable}
bind:method={data.config.suggestions.method}
/>
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
<div class="col-span-1">
<Suggestions
bind:enabled={data.config.suggestions.enable}
bind:method={data.config.suggestions.method}
/>
</div>
<div class="col-span-1">
<Claims bind:enabled={data.config.claims.showName} />
</div>
</div>

<button class="variant-filled-primary btn mt-2" type="submit">
{#if saved}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/claims/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
out:send|local={{ key: item.id }}
animate:flip={{ duration: 200 }}
>
<ItemCard {item} showFor user={data.user} />
<ItemCard {item} showClaimedName showFor user={data.user} />
</div>
{/each}
{#each items.filter((item) => item.purchased) as item (item.id)}
Expand All @@ -51,7 +51,7 @@
out:send|local={{ key: item.id }}
animate:flip={{ duration: 200 }}
>
<ItemCard {item} showFor user={data.user} />
<ItemCard {item} showClaimedName showFor user={data.user} />
</div>
{/each}
</div>
Expand Down

0 comments on commit 3c63dd8

Please sign in to comment.