Skip to content

Commit

Permalink
feat(frontend): option to add default odk creds for organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Feb 1, 2024
1 parent 82af00a commit 24c6e8a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ interface OrganisationValues {
description: string;
url: string;
type: number;
odk_central_url: string;
odk_central_user: string;
odk_central_password: string;
}
interface ValidationErrors {
logo?: string;
name?: string;
description?: string;
url?: string;
type?: string;
odk_central_url?: string;
odk_central_user?: string;
odk_central_password?: string;
}

function isValidUrl(url: string) {
Expand All @@ -25,21 +31,28 @@ function isValidUrl(url: string) {
function OrganisationAddValidation(values: OrganisationValues) {
const errors: ValidationErrors = {};

// if (!values?.logo) {
// errors.logo = 'Logo is Required.';
// }
if (!values?.name) {
errors.name = 'Name is Required.';
}

if (!values?.description) {
errors.description = 'Description is Required.';
}

if (!values?.url) {
errors.url = 'Organization Url is Required.';
} else if (!isValidUrl(values.url)) {
errors.url = 'Invalid URL.';
}

if (values?.odk_central_url && !isValidUrl(values.odk_central_url)) {
errors.odk_central_url = 'Invalid URL.';
}

// if (!values?.logo) {
// errors.logo = 'Logo is Required.';
// }

return errors;
}

Expand Down
9 changes: 0 additions & 9 deletions src/frontend/src/models/organisation/organisationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,3 @@ export interface GetOrganisationDataModel {
logo: string;
url: string;
}
export interface PostOrganisationDataModel {
name: string;
slug: string;
description: string;
type: number;
id: number;
logo: string;
url: string;
}
63 changes: 63 additions & 0 deletions src/frontend/src/views/CreateOrganisation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,69 @@ const CreateOrganisationForm = () => {
FormHelperTextProps={inputFormStyles()}
/>
</CoreModules.FormControl>
<CoreModules.FormControl sx={{ width: '100%' }}>
<CoreModules.Box sx={{ display: 'flex', flexDirection: 'row' }}>
<CoreModules.FormLabel sx={{}} component="h3">
ODK Central URL (Optional)
</CoreModules.FormLabel>
</CoreModules.Box>
<CoreModules.TextField
id="odk_central_url"
label=""
variant="filled"
value={values.odk_central_url}
onChange={(e) => {
handleCustomChange('odk_central_url', e.target.value);
}}
fullWidth
multiline
rows={1}
helperText={errors.odk_central_url}
FormHelperTextProps={inputFormStyles()}
/>
</CoreModules.FormControl>
<CoreModules.FormControl sx={{ width: '100%' }}>
<CoreModules.Box sx={{ display: 'flex', flexDirection: 'row' }}>
<CoreModules.FormLabel sx={{}} component="h3">
ODK Central User (Optional)
</CoreModules.FormLabel>
</CoreModules.Box>
<CoreModules.TextField
id="odk_central_user"
label=""
variant="filled"
value={values.odk_central_user}
onChange={(e) => {
handleCustomChange('odk_central_user', e.target.value);
}}
fullWidth
multiline
rows={1}
helperText={errors.odk_central_user}
FormHelperTextProps={inputFormStyles()}
/>
</CoreModules.FormControl>
<CoreModules.FormControl sx={{ width: '100%' }}>
<CoreModules.Box sx={{ display: 'flex', flexDirection: 'row' }}>
<CoreModules.FormLabel sx={{}} component="h3">
ODK Central Password (Optional)
</CoreModules.FormLabel>
</CoreModules.Box>
<CoreModules.TextField
id="odk_central_password"
label=""
variant="filled"
value={values.odk_central_password}
onChange={(e) => {
handleCustomChange('odk_central_password', e.target.value);
}}
fullWidth
multiline
rows={1}
helperText={errors.odk_central_password}
FormHelperTextProps={inputFormStyles()}
/>
</CoreModules.FormControl>
<CoreModules.FormControl fullWidth margin="normal" variant="filled" sx={{ gap: 1 }}>
<CoreModules.Box
sx={{
Expand Down

0 comments on commit 24c6e8a

Please sign in to comment.