Skip to content

Commit

Permalink
Show notification when opening home tab if user is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Jan 2, 2025
1 parent 9ba61fc commit aa1ce51
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
36 changes: 36 additions & 0 deletions app/src/gui/home-tab/home-tab.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Controller, Logger } from "@nestjs/common";
import { AllMiddlewareArgs, StringIndexed } from "@slack/bolt";
import { Actions, Button, Header, HomeTab, Section } from "slack-block-builder";
import { Appendable, ViewBlockBuilder } from "slack-block-builder/dist/internal";
import BoltAction from "../../bolt/decorators/bolt-action.decorator";
import BoltEvent from "../../bolt/decorators/bolt-event.decorator";
import Action from "../../bolt/enums/action.enum";
import Event from "../../bolt/enums/event.enum";
import { BoltActionArgs } from "../../bolt/types/bolt-action-args.type";
import { WebClient } from "../../bolt/types/web-client.type";
import { UserSettingsService } from "../../entities/user-settings/user-settings.service";
import { UserService } from "../../entities/user/user.service";
import { HomeTabService } from "./home-tab.service";
import { PresenceView } from "./views/presence/presence.view";
import { RegistrationView } from "./views/registration/registration.view";
Expand All @@ -28,11 +31,19 @@ export class HomeTabController {
private registrationView: RegistrationView,
private settingsView: SettingsView,
private userSettingsService: UserSettingsService,
private userService: UserService,
) {}

@BoltEvent(Event.APP_HOME_OPENED)
async getView({ client, context }: AllMiddlewareArgs<StringIndexed>) {
this.logger.debug(Event.APP_HOME_OPENED);

const { userId } = context;

if (!(await this.userService.findPopulatedBySlackId(userId))) {
return this.showUserNotFoundView(userId, client);
}

const { selectedView } = await this.userSettingsService.findForUser(userId);
let content: Appendable<ViewBlockBuilder> = [];

Expand Down Expand Up @@ -111,4 +122,29 @@ export class HomeTabController {
const content = await contentFactory();
this.homeTabService.update(actionArgs, content);
}

private async showUserNotFoundView(userId: string, client: WebClient) {
await client.views.publish({
user_id: userId,
view: HomeTab()
.blocks(
Header({ text: ":sos: Käyttäjää ei löytynyt!" }),
Section({
text:
"Käyttäjääsi ei löydy Kaikun tietokannasta. Mikäli olet tuotantoympäristössä, " +
"tämä viittaa vakavaan virheeseen, koska käyttäjien synkronoinnin pitäisi tapahtua " +
"automaattisesti. Kehitysympäristössä synkronointia ei tehdä automaattisesti " +
"API-rajoitusten vuoksi. Voit synkronoida käyttäjät klikkaamalla alla olevaa nappia " +
"ja lataamalla tämän näkymän uudelleen.",
}),
Actions().elements(
Button({
text: ":recycle: Sync Users",
actionId: Action.SYNC_USERS,
}),
),
)
.buildToObject(),
});
}
}
12 changes: 7 additions & 5 deletions app/src/gui/home-tab/home-tab.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AuthorizationModule } from "../../authorization/authorization.module";
import { ConfigModule } from "../../common/config/config.module";
import { OfficeModule } from "../../entities/office/office.module";
import { UserSettingsModule } from "../../entities/user-settings/user-settings.module";
import { UserModule } from "../../entities/user/user.module";
import { DevUiModule } from "../dev/dev-ui.module";
import { HomeTabControls } from "./home-tab-controls";
import { HomeTabController } from "./home-tab.controller";
Expand All @@ -14,14 +15,15 @@ import { SettingsView } from "./views/settings/settings.view";

@Module({
imports: [
AuthorizationModule,
ConfigModule,
DevUiModule,
RegistrationViewModule,
OfficeModule,
PresenceViewModule,
ConfigModule,
UserSettingsModule,
RegistrationViewModule,
SettingsViewModule,
OfficeModule,
AuthorizationModule,
UserModule,
UserSettingsModule,
],
providers: [HomeTabService, HomeTabControls, SettingsView],
controllers: [HomeTabController],
Expand Down

0 comments on commit aa1ce51

Please sign in to comment.