Skip to content

Commit

Permalink
Merge pull request #1194 from cultuurnet/bugfix/PPF-498
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen authored Jun 25, 2024
2 parents eb1dbe5 + dfa88f9 commit f16de74
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions resources/ts/Pages/Integrations/New.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { FormEvent, ReactNode } from "react";
import React from "react";
import { useState } from "react";
import React, { useEffect, useState } from "react";
import { router, useForm } from "@inertiajs/react";
import Layout from "../../layouts/Layout";
import { Heading } from "../../Components/Heading";
Expand Down Expand Up @@ -33,12 +32,6 @@ const New = ({ subscriptions }: Props) => {
const { t } = useTranslation();
const { i18n } = useTranslation();

const freeSubscriptionId = subscriptions.find(
(subscription) =>
subscription.integrationType === IntegrationType.EntryApi &&
subscription.price === 0
)?.id;

const basicSubscriptionIds = subscriptions
.filter(
(subscription) => subscription.category === SubscriptionCategory.Basic
Expand All @@ -53,10 +46,7 @@ const New = ({ subscriptions }: Props) => {

const initialFormValues = {
integrationType: activeType,
subscriptionId:
activeType === IntegrationType.EntryApi && !!freeSubscriptionId
? freeSubscriptionId
: "",
subscriptionId: "",
integrationName: "",
description: "",
website: "",
Expand All @@ -77,6 +67,17 @@ const New = ({ subscriptions }: Props) => {
const { data, setData, errors, hasErrors, post, processing } =
useForm(initialFormValues);

useEffect(() => {
const freeSubscriptionId = subscriptions.find(
(subscription) =>
subscription.integrationType === activeType &&
subscription.category === SubscriptionCategory.Free
)?.id;

setData("subscriptionId", freeSubscriptionId ?? "");
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeType, subscriptions]);

function handleSubmit(e: FormEvent<HTMLFormElement>) {
e.preventDefault();
post("/integrations", {
Expand Down

0 comments on commit f16de74

Please sign in to comment.