-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show notifications on registration failure (#51)
- Loading branch information
1 parent
1f57ea6
commit 20d6e5b
Showing
7 changed files
with
118 additions
and
8 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
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
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,42 @@ | ||
<script lang="ts"> | ||
import { Toast } from 'flowbite-svelte'; | ||
import { | ||
CheckCircleSolid, | ||
CloseCircleSolid, | ||
ExclamationCircleSolid | ||
} from 'flowbite-svelte-icons'; | ||
import type { ComponentType } from 'svelte'; | ||
import { dismissMessage, type Message } from '~/lib/messages'; | ||
const messageMapping: { | ||
[type: string]: { icon: ComponentType; color: 'blue' | 'green' | 'red' }; | ||
} = { | ||
success: { | ||
icon: CheckCircleSolid, | ||
color: 'green' | ||
}, | ||
info: { | ||
icon: ExclamationCircleSolid, | ||
color: 'blue' | ||
}, | ||
error: { | ||
icon: CloseCircleSolid, | ||
color: 'red' | ||
} | ||
}; | ||
export let message: Message; | ||
</script> | ||
|
||
{#if message} | ||
{@const color = messageMapping[message.type].color} | ||
{@const icon = messageMapping[message.type].icon} | ||
<div {...$$restProps}> | ||
<Toast {color} on:close={() => dismissMessage(message.id)}> | ||
<svelte:fragment slot="icon"> | ||
<svelte:component this={icon} class="h-5 w-5" /> | ||
</svelte:fragment> | ||
{message.message} | ||
</Toast> | ||
</div> | ||
{/if} |
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,9 @@ | ||
// @vitest-environment jsdom | ||
import { render } from '@testing-library/svelte'; | ||
import { expect, it } from 'vitest'; | ||
import Message from './Message.svelte'; | ||
|
||
it('renders OK', () => { | ||
const { container } = render(Message); | ||
expect(container).toBeTruthy(); | ||
}); |
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,48 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export type Message = { | ||
id?: string; | ||
type: 'success' | 'info' | 'error'; | ||
message: string; | ||
}; | ||
|
||
export type MessageBox = { | ||
[id: string]: Message; | ||
}; | ||
|
||
export const messageBox = writable<MessageBox>({}); | ||
|
||
/** | ||
* Put message to message box. | ||
* @param message Message to put. If `.id` is not set, random generated ID will be used. | ||
* @returns ID of message. | ||
*/ | ||
export function putMessage(message: Message): string { | ||
const id = message.id ?? Math.random().toString(36).substring(2); | ||
messageBox.update((box) => { | ||
box[id] = { id, ...message }; | ||
return box; | ||
}); | ||
return id; | ||
} | ||
|
||
/** | ||
* Dismiss message with ID. | ||
* @param id ID of message. | ||
*/ | ||
export function dismissMessage(id?: string) { | ||
if (!id) return; | ||
|
||
messageBox.update((box) => { | ||
delete box[id]; | ||
return box; | ||
}); | ||
} | ||
|
||
/* c8 ignore start */ | ||
if (import.meta.vitest) { | ||
const { describe } = import.meta.vitest; | ||
|
||
describe.todo('To Do'); | ||
} | ||
/* c8 ignore stop */ |
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