Skip to content

Commit

Permalink
Merge pull request #765 from eduhub-org/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
steffen74 authored Oct 13, 2023
2 parents d20d5c2 + cdfaf1a commit eff55db
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."AppSettings" add column "app" text
not null unique;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."AppSettings" rename column "appName" to "app";
comment on column "public"."AppSettings"."app" is NULL;
Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "public"."AppSettings" ("appName", "bannerBackgroundColor", "bannerFontColor", "bannerTextDe", "bannerTextEn")
VALUES (E'edu', DEFAULT, DEFAULT, DEFAULT, DEFAULT);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,8 +48,9 @@ const ManageAppSettingsOverview: FC = () => {
error: appSettingsError,
refetch: refetchAppSettings,
} = useAdminQuery<AppSettings>(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({
Expand All @@ -66,32 +66,20 @@ const ManageAppSettingsOverview: FC = () => {
});

const [updateAppSettings] = useAdminMutation<UpdateAppSettings, UpdateAppSettingsVariables>(UPDATE_APP_SETTINGS);
const [insertAppSettings] = useAdminMutation<InsertAppSettings, InsertAppSettingsVariables>(INSERT_APP_SETTINGS);

const onSubmit: SubmitHandler<Inputs> = 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));
Expand Down
6 changes: 4 additions & 2 deletions frontend-nx/apps/edu-hub/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export const Page: FC<PageProps> = ({ children, className }) => {
loading: appSettingsLoading,
error: appSettingsError,
} = useRoleQuery<AppSettings>(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);
}
Expand Down
14 changes: 11 additions & 3 deletions frontend-nx/apps/edu-hub/queries/__generated__/AppSettings.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 9 additions & 30 deletions frontend-nx/apps/edu-hub/queries/appSettings.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
}
`;

0 comments on commit eff55db

Please sign in to comment.