Skip to content

Announcements #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Announcements #26

wants to merge 9 commits into from

Conversation

flomillot
Copy link
Contributor

@flomillot flomillot commented Mar 29, 2024

Add the possibility to send an announcement to the connected users of other web app for a specified duration.

Comment on lines 60 to 69
[
MainPaths.announcements,
<TabNavLink
icon={<Announcement />}
label={<FormattedMessage id="appBar.tabs.announcement" />}
href={`/${MainPaths.announcements}`}
value={MainPaths.announcements}
key={`tab-${MainPaths.announcements}`}
/>,
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid storing ReactElement in a variable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just use the existing pattern, if you think we should refactor this, we need to do an other PR.
How bad is it ?

<Grid item>
<List sx={{ maxWidth: 1400 }}>
{announcements.map((announcement) => (
<ListItemAnnouncement {...announcement} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnnouncementItem ? And I think I prefer when the arguments are an object.
<AnnouncementItem item={announcement} /> ? I think it makes it more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer like this, for me this way is clearer.
export const ListItemAnnouncement: FunctionComponent<Announcement> = (
No need to define a new ListItemAnnouncementProps with just one item which is an Announcement...
It's already an item itself, so why giving an inner item prop ?
It follow the pattern ListItemText.
But if it's rly a bad way and if the second reviewer agree with you, I'll change it.

Comment on lines 22 to 36
<Grid item container spacing={2} direction="column">
<Grid item>
<AppBar position="static" color="default">
<Toolbar variant="dense">
<Button
onClick={() => setOpenDialog(true)}
variant="outlined"
startIcon={<AddCircleOutline />}
size="small"
>
{intl.formatMessage({ id: 'announcements.add' })}
</Button>
</Toolbar>
</AppBar>
</Grid>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract that in common component with Users ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok doing it


return (
//@ts-ignore because RHF TS is broken
<FormProvider validationSchema={formSchema} {...formMethods}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure ? It's not just that we shouldn't define this property ? Schema is in the yup resolver already, no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm wondering if we don't do it wrong since the start haha

import { useAnnouncements } from './useAnnouncements';
import { ListItemAnnouncement } from './ListItemAnnouncement';

const Announcements: FunctionComponent = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can separate in different components the top bar from the announcements list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm extracting the Topbar/Toolbar combo, you think about something else ?

},
};

// const formSchema: ObjectSchema<FormData> = yup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've let it for the reviewers to discuss about this issue because I don't really like all this, with the tsignore also...

Comment on lines +54 to +56
[HOURS, MINUTES],
[DAYS, MINUTES],
[DAYS, HOURS],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does that work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally I don't really know, it's not even in the doc, but like this we remove all cyclic dep combo

};

// const formSchema: ObjectSchema<FormData> = yup
export const formSchema = yup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we separate the formSchema from type definitions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean ?

@@ -95,3 +100,44 @@ export function addUser(sub: string): Promise<void> {
throw reason;
});
}

export function getAnnouncements(): Promise<AnnouncementServerData[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we catch errors and display snackBar ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I forgot you're right

Comment on lines 47 to 70
{
[DAYS]: getDurationUnitSchema(HOURS, MINUTES),
[HOURS]: getDurationUnitSchema(DAYS, MINUTES),
[MINUTES]: getDurationUnitSchema(DAYS, HOURS),
},
// to avoid cyclic dependencies
[
[HOURS, MINUTES],
[DAYS, MINUTES],
[DAYS, HOURS],
]
)
.required(),
})
.required();

function getDurationUnitSchema(otherUnitName1: string, otherUnitName2: string) {
return yup.number().when([otherUnitName1, otherUnitName2], {
is: (v1: number | null, v2: number | null) =>
v1 === null && v2 === null,
then: (schema) => schema.required(),
otherwise: (schema) => schema.nullable(),
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we simplify by saying at least one of these three is required ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how. We can do that for the validation but then the fields won't be red with "required" key word.

export const formSchema = yup
.object()
.shape({
[MESSAGE]: yup.string().max(100).required(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 is quite limiting, maybe double check with a PO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asked

@jonenst jonenst force-pushed the main branch 2 times, most recently from 35af5e1 to d93158a Compare April 11, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants