-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from yamitzky/feat/upcoming-reminder
Feat/upcoming reminder
- Loading branch information
Showing
11 changed files
with
599 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Card, CardBody, CardHeader } from '@nextui-org/react' | ||
import { ReminderTarget } from '@synk-cal/usecase' | ||
import { parseISO } from 'date-fns' | ||
import useLocale from '~/hooks/useLocale' | ||
|
||
type SerializedReminderTarget = Omit<ReminderTarget, 'sendAt'> & { | ||
sendAt: string | ||
} | ||
|
||
type Props = { | ||
reminders: SerializedReminderTarget[] | ||
className?: string | ||
} | ||
|
||
export function UpcomingReminders({ reminders, className }: Props) { | ||
const locale = useLocale() | ||
const sortedReminders = [...reminders].sort((a, b) => parseISO(a.sendAt).getTime() - parseISO(b.sendAt).getTime()) | ||
|
||
const dateTimeFormatter = new Intl.DateTimeFormat(locale, { | ||
month: 'numeric', | ||
day: 'numeric', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
hour12: false, | ||
}) | ||
|
||
return ( | ||
<Card className={className}> | ||
<CardHeader> | ||
<h2 className="text-lg font-semibold">{locale === 'ja' ? '今後のリマインダー' : 'Upcoming Reminders'}</h2> | ||
</CardHeader> | ||
<CardBody> | ||
<div className="flex flex-col gap-4"> | ||
{sortedReminders.length === 0 ? ( | ||
<p className="text-default-500">{locale === 'ja' ? 'リマインダーはありません' : 'No upcoming reminders'}</p> | ||
) : ( | ||
sortedReminders.map((reminder, index) => ( | ||
<div key={index} className="flex flex-col gap-1 p-4 border rounded"> | ||
<div className="text-sm text-default-500"> | ||
{reminder.sendAt} | ||
{locale === 'ja' | ||
? `${dateTimeFormatter.format(parseISO(reminder.sendAt))}に通知` | ||
: `Notify at ${dateTimeFormatter.format(parseISO(reminder.sendAt))}`} | ||
</div> | ||
<div className="text-default-700">{reminder.message}</div> | ||
<div className="text-xs text-default-400"> | ||
{locale === 'ja' ? '通知方法:' : 'Notification type: '} | ||
{reminder.notificationType} | ||
</div> | ||
</div> | ||
)) | ||
)} | ||
</div> | ||
</CardBody> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { AuthRepository, config } from '@synk-cal/core' | ||
import { IAPAuthRepository } from '@synk-cal/google' | ||
import { MockAuthRepository } from '@synk-cal/repository' | ||
|
||
export function getAuthRepository(): AuthRepository | undefined { | ||
if (config.AUTH_PROVIDER === 'google-iap') { | ||
return new IAPAuthRepository() | ||
} else if (config.AUTH_PROVIDER === 'mock') { | ||
const mockEmail = config.AUTH_MOCK_USER || '[email protected]' | ||
return new MockAuthRepository({ email: mockEmail }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './console_notification' | ||
export * from './global_reminder_settings' | ||
export * from './mock_auth' | ||
export * from './webhook_notification' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { User } from '@synk-cal/core' | ||
|
||
/** | ||
* Mock implementation of AuthRepository that returns a dummy user | ||
* with a specified email address | ||
*/ | ||
export class MockAuthRepository { | ||
email: string | ||
constructor({ email = '[email protected]' }: { email: string }) { | ||
this.email = email | ||
} | ||
|
||
async getUserFromHeader(_headers: Headers): Promise<User | undefined> { | ||
// Always return the configured user | ||
return { | ||
email: this.email, | ||
name: `Test User (${this.email})`, | ||
} | ||
} | ||
} |
Oops, something went wrong.