Skip to content

Commit 3346451

Browse files
committed
thunderstore-api: allow null values for team donation link
The backend uses Django's cursed null=True for saving the donation link, so submitting empty string will fail on save (or even earlier by the validation done by serializer) unless it is cast to null. At least earlier a design principle has been that API does what it does, and the clients should adjust their behaviour to match the API. It's also seems to be cleaner to do the casting here.
1 parent 0bed199 commit 3346451

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

apps/cyberstorm-remix/app/settings/teams/team/tabs/Profile/Profile.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ function ProfileForm(props: { team: TeamDetails }) {
9090
InputErrors
9191
>({
9292
inputs: formInputs,
93+
refiner: async (inputs: typeof formInputs) => ({
94+
donation_link: nullForEmptyString(inputs.donation_link),
95+
}),
9396
submitor,
9497
onSubmitSuccess: () => {
9598
toast.addToast({
@@ -120,7 +123,7 @@ function ProfileForm(props: { team: TeamDetails }) {
120123
<NewTextInput
121124
name={"donation_link"}
122125
placeholder={"https://"}
123-
value={formInputs.donation_link}
126+
value={formInputs.donation_link ?? ""}
124127
onChange={(e) =>
125128
updateFormFieldState({
126129
field: "donation_link",
@@ -140,3 +143,6 @@ function ProfileForm(props: { team: TeamDetails }) {
140143
}
141144

142145
ProfileForm.displayName = "ProfileForm";
146+
147+
const nullForEmptyString = (value: string | null): string | null =>
148+
value?.trim() === "" ? null : value;

packages/thunderstore-api/src/schemas/requestSchemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ export type TeamDetailsEditRequestParams = z.infer<
622622
>;
623623

624624
export const teamDetailsEditRequestDataSchema = z.object({
625-
donation_link: z.string().min(1).max(1024),
625+
donation_link: z.string().min(1).max(1024).nullable(),
626626
});
627627

628628
export type TeamDetailsEditRequestData = z.infer<

packages/thunderstore-api/src/schemas/responseSchemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export type MarkdownRenderResponseData = z.infer<
353353

354354
// TeamDetailsEditResponse
355355
export const teamDetailsEditResponseSchema = z.object({
356-
donation_link: z.string().min(1).max(1024),
356+
donation_link: z.string().min(1).max(1024).nullable(),
357357
});
358358

359359
export type TeamDetailsEditResponseData = z.infer<

0 commit comments

Comments
 (0)