Skip to content

Commit

Permalink
feat: better wording at phone edit
Browse files Browse the repository at this point in the history
  • Loading branch information
dodyagung committed Apr 9, 2024
1 parent 2f8cf76 commit ab39f55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/sale/sale.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { FALLBACK_MESSAGE } from './sale.constant';
type Hideable<B> = B & { hide?: boolean };
type HideableIKBtn = Hideable<InlineKeyboardButton>;

const extra = (keyboard: HideableIKBtn[][]): ExtraEditMessageText => {
const extraWithoutKeyboard = (): ExtraEditMessageText => {
return {
parse_mode: 'MarkdownV2',
link_preview_options: {
is_disabled: true,
},
reply_markup: Markup.inlineKeyboard(keyboard).reply_markup,
};
};

const extraWithKeyboard = (
keyboard: HideableIKBtn[][],
): ExtraEditMessageText => {
return Object.assign(extraWithoutKeyboard(), {
reply_markup: Markup.inlineKeyboard(keyboard).reply_markup,
});
};

export const leaveScene = (ctx: SceneContext): void => {
sendMessageWithoutKeyboard(ctx, FALLBACK_MESSAGE);
ctx.scene.leave();
Expand All @@ -28,13 +35,13 @@ export const sendMessageWithKeyboard = async (
keyboard: HideableIKBtn[][],
): Promise<void> => {
await (ctx.callbackQuery
? ctx.editMessageText(message, extra(keyboard))
: ctx.reply(message, extra(keyboard)));
? ctx.editMessageText(message, extraWithKeyboard(keyboard))
: ctx.reply(message, extraWithKeyboard(keyboard)));
};

export const sendMessageWithoutKeyboard = (
ctx: SceneContext,
message: string,
): void => {
ctx.reply(message);
ctx.reply(message, extraWithoutKeyboard());
};
11 changes: 6 additions & 5 deletions src/sale/scene/profile/phone/phone_edit.scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Message,
} from 'nestjs-telegraf';
import { SceneContext } from 'telegraf/scenes';
import { Markup, Scenes } from 'telegraf';
import { Markup } from 'telegraf';
import {
sendMessageWithKeyboard,
sendMessageWithoutKeyboard,
Expand Down Expand Up @@ -37,10 +37,11 @@ export class PhoneEditScene {
@Hears(/.+/)
onFallback(@Ctx() ctx: SceneContext, @Message() msg: { text: string }): void {
this.saleService.editPhone(ctx.from!.id.toString(), msg.text);
sendMessageWithoutKeyboard(
ctx,
`Successfuly edited the phone with ${msg.text}!`,
);

let message = `✅ Success\n\n`;
message += `Your phone number has been successfully edited to \`${msg.text}\`\\.`;
sendMessageWithoutKeyboard(ctx, message);

ctx.scene.enter('PROFILE_SCENE');
}
}

0 comments on commit ab39f55

Please sign in to comment.