diff --git a/backend/migrations/default/1697138898623_alter_table_public_AppSettings_add_column_app/down.sql b/backend/migrations/default/1697138898623_alter_table_public_AppSettings_add_column_app/down.sql new file mode 100644 index 000000000..2d7030472 --- /dev/null +++ b/backend/migrations/default/1697138898623_alter_table_public_AppSettings_add_column_app/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."AppSettings" add column "app" text +-- not null unique; diff --git a/backend/migrations/default/1697138898623_alter_table_public_AppSettings_add_column_app/up.sql b/backend/migrations/default/1697138898623_alter_table_public_AppSettings_add_column_app/up.sql new file mode 100644 index 000000000..08fdd1a08 --- /dev/null +++ b/backend/migrations/default/1697138898623_alter_table_public_AppSettings_add_column_app/up.sql @@ -0,0 +1,2 @@ +alter table "public"."AppSettings" add column "app" text + not null unique; diff --git a/backend/migrations/default/1697138989558_alter_table_public_AppSettings_alter_column_app/down.sql b/backend/migrations/default/1697138989558_alter_table_public_AppSettings_alter_column_app/down.sql new file mode 100644 index 000000000..5113cdc4a --- /dev/null +++ b/backend/migrations/default/1697138989558_alter_table_public_AppSettings_alter_column_app/down.sql @@ -0,0 +1,2 @@ +alter table "public"."AppSettings" rename column "appName" to "app"; +comment on column "public"."AppSettings"."app" is NULL; diff --git a/backend/migrations/default/1697138989558_alter_table_public_AppSettings_alter_column_app/up.sql b/backend/migrations/default/1697138989558_alter_table_public_AppSettings_alter_column_app/up.sql new file mode 100644 index 000000000..86cdf9b55 --- /dev/null +++ b/backend/migrations/default/1697138989558_alter_table_public_AppSettings_alter_column_app/up.sql @@ -0,0 +1,2 @@ +comment on column "public"."AppSettings"."app" is E'Name of the app to which the given settings are applied'; +alter table "public"."AppSettings" rename column "app" to "appName"; diff --git a/backend/migrations/default/1697139203652_insert_into_public_AppSettings/down.sql b/backend/migrations/default/1697139203652_insert_into_public_AppSettings/down.sql new file mode 100644 index 000000000..fced04ed8 --- /dev/null +++ b/backend/migrations/default/1697139203652_insert_into_public_AppSettings/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- INSERT INTO "public"."AppSettings" ("appName", "bannerBackgroundColor", "bannerFontColor", "bannerTextDe", "bannerTextEn") +-- VALUES (E'edu', DEFAULT, DEFAULT, DEFAULT, DEFAULT); diff --git a/backend/migrations/default/1697139203652_insert_into_public_AppSettings/up.sql b/backend/migrations/default/1697139203652_insert_into_public_AppSettings/up.sql new file mode 100644 index 000000000..4ad4457dc --- /dev/null +++ b/backend/migrations/default/1697139203652_insert_into_public_AppSettings/up.sql @@ -0,0 +1,2 @@ +INSERT INTO "public"."AppSettings" ("appName", "bannerBackgroundColor", "bannerFontColor", "bannerTextDe", "bannerTextEn") +VALUES (E'edu', DEFAULT, DEFAULT, DEFAULT, DEFAULT); diff --git a/frontend-nx/apps/edu-hub/components/ManageAppSettingsContent/ManageAppSettingsOverview.tsx b/frontend-nx/apps/edu-hub/components/ManageAppSettingsContent/ManageAppSettingsOverview.tsx index 849bb9321..f158fa3f8 100644 --- a/frontend-nx/apps/edu-hub/components/ManageAppSettingsContent/ManageAppSettingsOverview.tsx +++ b/frontend-nx/apps/edu-hub/components/ManageAppSettingsContent/ManageAppSettingsOverview.tsx @@ -10,9 +10,8 @@ import { useAdminMutation } from '../../hooks/authedMutation'; import { useAdminQuery } from '../../hooks/authedQuery'; import { UpdateAppSettingsVariables, UpdateAppSettings } from '../../queries/__generated__/UpdateAppSettings'; -import { APP_SETTINGS, INSERT_APP_SETTINGS, UPDATE_APP_SETTINGS } from '../../queries/appSettings'; +import { APP_SETTINGS, UPDATE_APP_SETTINGS } from '../../queries/appSettings'; import { AppSettings } from '../../queries/__generated__/AppSettings'; -import { InsertAppSettings, InsertAppSettingsVariables } from '../../queries/__generated__/InsertAppSettings'; type Inputs = { // backgroundImageURL: string; @@ -49,8 +48,9 @@ const ManageAppSettingsOverview: FC = () => { error: appSettingsError, refetch: refetchAppSettings, } = useAdminQuery(APP_SETTINGS, { + variables: { appName: 'edu' }, onCompleted: (data) => { - const appSettings = data.AppSettings[0]; + const [appSettings] = data.AppSettings; // Using array destructuring to get the first item if (appSettings) { reset({ @@ -66,32 +66,20 @@ const ManageAppSettingsOverview: FC = () => { }); const [updateAppSettings] = useAdminMutation(UPDATE_APP_SETTINGS); - const [insertAppSettings] = useAdminMutation(INSERT_APP_SETTINGS); const onSubmit: SubmitHandler = async (data) => { try { - const variables = { - // backgroundImageURL: data.backgroundImageURL, - bannerBackgroundColor: data.bannerBackgroundColor, - bannerFontColor: data.bannerFontColor, - bannerTextDe: data.bannerTextDe, - bannerTextEn: data.bannerTextEn, - }; - - if (appSettingsData.AppSettings && appSettingsData.AppSettings[0]) { - await updateAppSettings({ - variables: { - ...variables, - id: appSettingsData.AppSettings[0].id, - }, - }); - } else { - await insertAppSettings({ - variables: { - ...variables, - }, - }); - } + await updateAppSettings({ + variables: { + id: appSettingsData.AppSettings[0].id, + appName: 'edu', + // backgroundImageURL: data.backgroundImageURL, + bannerBackgroundColor: data.bannerBackgroundColor, + bannerFontColor: data.bannerFontColor, + bannerTextDe: data.bannerTextDe, + bannerTextEn: data.bannerTextEn, + }, + }); refetchAppSettings(); await new Promise((resolve) => setTimeout(resolve, 1000)); diff --git a/frontend-nx/apps/edu-hub/components/Page.tsx b/frontend-nx/apps/edu-hub/components/Page.tsx index 214672f96..7241470d8 100644 --- a/frontend-nx/apps/edu-hub/components/Page.tsx +++ b/frontend-nx/apps/edu-hub/components/Page.tsx @@ -43,9 +43,11 @@ export const Page: FC = ({ children, className }) => { loading: appSettingsLoading, error: appSettingsError, } = useRoleQuery(APP_SETTINGS, { + variables: { appName: 'edu' }, onCompleted: (data) => { - const appSettings = data.AppSettings[0]; - if (appSettings) { + const [appSettings] = data.AppSettings; // Using array destructuring to get the first item + + if (appSettings.bannerTextDe && appSettings.bannerTextEn) { if (lang === 'de') handleBanner('bannerContentDe', appSettings.bannerTextDe); else if (lang === 'en') handleBanner('bannerContentEn', appSettings.bannerTextEn); } diff --git a/frontend-nx/apps/edu-hub/queries/__generated__/AppSettings.ts b/frontend-nx/apps/edu-hub/queries/__generated__/AppSettings.ts index 25418c921..c63d01257 100644 --- a/frontend-nx/apps/edu-hub/queries/__generated__/AppSettings.ts +++ b/frontend-nx/apps/edu-hub/queries/__generated__/AppSettings.ts @@ -9,10 +9,15 @@ export interface AppSettings_AppSettings { __typename: "AppSettings"; + id: number; + /** + * Name of the app to which the given settings are applied + */ + appName: string; /** * Homepage background image */ - backgroundImageURL: string; + backgroundImageURL: string | null; /** * Background color for the dismissiable banner displayed on the homepage */ @@ -29,11 +34,10 @@ export interface AppSettings_AppSettings { * English version for the text of a dismissiable banner on the homepage */ bannerTextEn: string | null; - id: number; /** * Preview image that is shared with links */ - previewImageURL: string; + previewImageURL: string | null; } export interface AppSettings { @@ -42,3 +46,7 @@ export interface AppSettings { */ AppSettings: AppSettings_AppSettings[]; } + +export interface AppSettingsVariables { + appName: string; +} diff --git a/frontend-nx/apps/edu-hub/queries/__generated__/InsertAppSettings.ts b/frontend-nx/apps/edu-hub/queries/__generated__/InsertAppSettings.ts deleted file mode 100644 index d8695f1b3..000000000 --- a/frontend-nx/apps/edu-hub/queries/__generated__/InsertAppSettings.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL mutation operation: InsertAppSettings -// ==================================================== - -export interface InsertAppSettings_insert_AppSettings_one { - __typename: "AppSettings"; - id: number; -} - -export interface InsertAppSettings { - /** - * insert a single row into the table: "AppSettings" - */ - insert_AppSettings_one: InsertAppSettings_insert_AppSettings_one | null; -} - -export interface InsertAppSettingsVariables { - bannerBackgroundColor?: string | null; - bannerFontColor?: string | null; - bannerTextDe?: string | null; - bannerTextEn?: string | null; -} diff --git a/frontend-nx/apps/edu-hub/queries/__generated__/UpdateAppSettings.ts b/frontend-nx/apps/edu-hub/queries/__generated__/UpdateAppSettings.ts index d9a3a433f..2137f7cf2 100644 --- a/frontend-nx/apps/edu-hub/queries/__generated__/UpdateAppSettings.ts +++ b/frontend-nx/apps/edu-hub/queries/__generated__/UpdateAppSettings.ts @@ -9,6 +9,11 @@ export interface UpdateAppSettings_update_AppSettings_by_pk { __typename: "AppSettings"; + id: number; + /** + * Name of the app to which the given settings are applied + */ + appName: string; /** * Background color for the dismissiable banner displayed on the homepage */ @@ -25,7 +30,6 @@ export interface UpdateAppSettings_update_AppSettings_by_pk { * English version for the text of a dismissiable banner on the homepage */ bannerTextEn: string | null; - id: number; } export interface UpdateAppSettings { @@ -36,9 +40,10 @@ export interface UpdateAppSettings { } export interface UpdateAppSettingsVariables { + id: number; + appName: string; bannerBackgroundColor?: string | null; bannerFontColor?: string | null; bannerTextDe?: string | null; bannerTextEn?: string | null; - id: number; } diff --git a/frontend-nx/apps/edu-hub/queries/appSettings.ts b/frontend-nx/apps/edu-hub/queries/appSettings.ts index 636b2820e..7deb3a30a 100644 --- a/frontend-nx/apps/edu-hub/queries/appSettings.ts +++ b/frontend-nx/apps/edu-hub/queries/appSettings.ts @@ -1,33 +1,35 @@ import { gql } from '@apollo/client'; export const APP_SETTINGS = gql` - query AppSettings { - AppSettings { + query AppSettings($appName: String!) { + AppSettings(where: { appName: { _eq: $appName } }) { + id + appName backgroundImageURL bannerBackgroundColor bannerFontColor bannerTextDe bannerTextEn - id previewImageURL } } `; - export const UPDATE_APP_SETTINGS = gql` mutation UpdateAppSettings( + $id: Int! + $appName: String! # $backgroundImageURL: String $bannerBackgroundColor: String $bannerFontColor: String $bannerTextDe: String $bannerTextEn: String - $id: Int! # $previewImageURL: String ) { update_AppSettings_by_pk( pk_columns: { id: $id } _set: { + appName: $appName # backgroundImageURL: $backgroundImageURL bannerBackgroundColor: $bannerBackgroundColor bannerFontColor: $bannerFontColor @@ -36,37 +38,14 @@ export const UPDATE_APP_SETTINGS = gql` # previewImageURL: $previewImageURL } ) { + id + appName # backgroundImageURL bannerBackgroundColor bannerFontColor bannerTextDe bannerTextEn - id # previewImageURL } } `; - - -export const INSERT_APP_SETTINGS = gql` - mutation InsertAppSettings ( - $bannerBackgroundColor: String - $bannerFontColor: String - $bannerTextDe: String - $bannerTextEn: String - # $backgroundImageURL: String - # $previewImageURL: String - ){ - insert_AppSettings_one( - object: { - bannerBackgroundColor: $bannerBackgroundColor - bannerFontColor: $bannerFontColor - bannerTextDe: $bannerTextDe - bannerTextEn: $bannerTextEn - # backgroundImageURL: $backgroundImageURL - # previewImageURL: $previewImageURL - }) { - id - } - } -`; \ No newline at end of file