Skip to content

Commit

Permalink
Merge pull request #180 from onehealthtoolkit/fix_issues
Browse files Browse the repository at this point in the history
#179 #176 #175 add user address field.
  • Loading branch information
pphetra authored Feb 12, 2024
2 parents f2d4c4b + c8d9408 commit 4442e59
Show file tree
Hide file tree
Showing 24 changed files with 336 additions and 7 deletions.
14 changes: 14 additions & 0 deletions components/admin/profile/updateInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ const ProfileInfoUpdate = () => {
/>
<ErrorText>{errors.telephone}</ErrorText>
</Field>
<Field $size="half">
<Label htmlFor="address">
{t("form.label.address", "Address")}
</Label>
<TextInput
id="address"
type="text"
placeholder={t("form.placeholder.address", "Address")}
onChange={evt => (viewModel.address = evt.target.value)}
disabled={viewModel.isSubmitting}
value={viewModel.address}
/>
<ErrorText>{errors.address}</ErrorText>
</Field>
</FieldGroup>
{viewModel.submitError.length > 0 && (
<FormMessage>{viewModel.submitError}</FormMessage>
Expand Down
18 changes: 17 additions & 1 deletion components/admin/profile/updateInfoViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class ProfileUpdateInfoViewModel extends BaseFormViewModel {
_firstName: string = "";
_lastName: string = "";
_telephone: string = "";
_address: string = "";

constructor(readonly me: Me, readonly profileService: IProfileService) {
super();
Expand All @@ -18,6 +19,8 @@ export class ProfileUpdateInfoViewModel extends BaseFormViewModel {
lastName: computed,
_telephone: observable,
telephone: computed,
_address: observable,
address: computed,
save: action,
validate: action,
});
Expand All @@ -30,6 +33,7 @@ export class ProfileUpdateInfoViewModel extends BaseFormViewModel {
this.firstName = this.me.firstName;
this.lastName = this.me.lastName;
this.telephone = this.me.telephone || "";
this.address = this.me.address || "";
}

public get firstName(): string {
Expand Down Expand Up @@ -65,6 +69,17 @@ export class ProfileUpdateInfoViewModel extends BaseFormViewModel {
}
}

public get address(): string {
return this._address;
}
public set address(value: string) {
this._address = value;
delete this.fieldErrors["address"];
if (this.submitError.length > 0) {
this.submitError = "";
}
}

public async save(): Promise<boolean> {
this.isSubmitting = true;

Expand All @@ -91,7 +106,8 @@ export class ProfileUpdateInfoViewModel extends BaseFormViewModel {
return this.profileService.updateProfile(
this.firstName,
this.lastName,
this.telephone
this.telephone,
this.address
);
}

Expand Down
11 changes: 11 additions & 0 deletions components/admin/user/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ const UserCreate = () => {
/>
<ErrorText>{errors.telephone}</ErrorText>
</Field>
<Field $size="half">
<Label htmlFor="address">{t("form.label.address", "Address")}</Label>
<TextInput
id="address"
type="text"
placeholder={t("form.placeholder.address", "Address")}
onChange={evt => (viewModel.address = evt.target.value)}
disabled={isSubmitting}
/>
<ErrorText>{errors.address}</ErrorText>
</Field>
<Field $size="half">
<Label htmlFor="role">{t("form.label.role", "Role")}</Label>
<Select
Expand Down
1 change: 1 addition & 0 deletions components/admin/user/createViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class UserCreateViewModel extends UserViewModel {
this.lastName,
this.email,
this.telephone,
this.address,
this.role
);
}
Expand Down
25 changes: 25 additions & 0 deletions components/admin/user/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ const UserUpdate = () => {
[t, viewModel]
);

const addressField = useMemo(
() => (
<Observer>
{() => (
<Field $size="half">
<Label htmlFor="address">
{t("form.label.address", "Address")}
</Label>
<TextInput
id="address"
type="text"
placeholder={t("form.placeholder.address", "Address")}
onChange={evt => (viewModel.address = evt.target.value)}
disabled={viewModel.isSubmitting}
value={viewModel.address}
/>
<ErrorText>{viewModel.fieldErrors.address}</ErrorText>
</Field>
)}
</Observer>
),
[t, viewModel]
);

const roleField = useMemo(
() => (
<Observer>
Expand Down Expand Up @@ -224,6 +248,7 @@ const UserUpdate = () => {
{lastNameField}
{emailField}
{telephoneField}
{addressField}
{roleField}
</FieldGroup>
{viewModel.submitError.length > 0 && (
Expand Down
2 changes: 2 additions & 0 deletions components/admin/user/updateViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class UserUpdateViewModel extends UserViewModel {
this.lastName = data.lastName;
this.email = data.email;
this.telephone = data.telephone || "";
this.address = data.address || "";
this.role = data.role || "";
this.authorityId = data.authorityId || 0;
}
Expand All @@ -35,6 +36,7 @@ export class UserUpdateViewModel extends UserViewModel {
this.lastName,
this.email,
this.telephone,
this.address,
this.role
);
}
Expand Down
14 changes: 14 additions & 0 deletions components/admin/user/userViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export abstract class UserViewModel extends BaseFormViewModel {
_lastName: string = "";
_email: string = "";
_telephone: string = "";
_address: string = "";
_role: string = AccountsAuthorityUserRoleChoices.Rep;
constructor(userService: IUserService) {
super();
Expand All @@ -30,6 +31,8 @@ export abstract class UserViewModel extends BaseFormViewModel {
email: computed,
_telephone: observable,
telephone: computed,
_address: observable,
address: computed,
_role: observable,
role: computed,
save: action,
Expand Down Expand Up @@ -104,6 +107,17 @@ export abstract class UserViewModel extends BaseFormViewModel {
}
}

public get address(): string {
return this._address;
}
public set address(value: string) {
this._address = value;
delete this.fieldErrors["address"];
if (this.submitError.length > 0) {
this.submitError = "";
}
}

public get role(): string {
return this._role;
}
Expand Down
9 changes: 9 additions & 0 deletions components/admin/user/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ const UserView = () => {
</th>
<td className="px-6 py-4">{viewModel.data.telephone}</td>
</tr>
<tr className="border-b dark:bg-gray-800 dark:border-gray-700 odd:bg-white even:bg-gray-50 odd:dark:bg-gray-800 even:dark:bg-gray-700">
<th
scope="row"
className="px-6 py-4 font-medium text-gray-900 dark:text-white whitespace-nowrap"
>
{t("form.label.address", "Address")}
</th>
<td className="px-6 py-4">{viewModel.data.address}</td>
</tr>
<tr>
<th
scope="row"
Expand Down
2 changes: 1 addition & 1 deletion components/auth/register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Register = () => {
alt="img"
/>
</div>
<div className="flex items-center justify-center p-6 sm:p-12 md:w-1/2">
<div className="h-screen flex items-center justify-center p-6 sm:p-12 md:w-1/2 overflow-y-auto">
<div className="w-full">
<h1 className="mb-4 text-2xl font-bold text-center text-gray-700">
{t("title.signup", "Sing Up")}
Expand Down
11 changes: 11 additions & 0 deletions components/auth/register/registerUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ const RegisterUser: React.FC<RegisterUserProps> = ({ viewModel }) => {
/>
<ErrorText>{errors.telephone}</ErrorText>
</Field>
<Field $size="full">
<Label htmlFor="address">{t("form.label.address", "Address")}</Label>
<TextInput
id="address"
type="text"
placeholder={t("form.placeholder.address", "Address")}
onChange={evt => (viewModel.address = evt.target.value)}
disabled={isSubmitting}
/>
<ErrorText>{errors.address}</ErrorText>
</Field>
{viewModel.submitError.length > 0 && (
<FormMessage>{viewModel.submitError}</FormMessage>
)}
Expand Down
17 changes: 16 additions & 1 deletion components/auth/register/viewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class RegisterViewModel {
_lastName: string = "";
_email: string = "";
_telephone: string = "";
_address: string = "";
_authorityName: string = "";

fieldErrors: { [key: string]: string } = {};
Expand Down Expand Up @@ -57,6 +58,8 @@ export class RegisterViewModel {
email: computed,
_telephone: observable,
telephone: computed,
_address: observable,
address: computed,
fieldErrors: observable,
submitError: observable,
checkInvitationCode: action,
Expand Down Expand Up @@ -162,6 +165,17 @@ export class RegisterViewModel {
}
}

public get address(): string {
return this._address;
}
public set address(value: string) {
this._address = value;
delete this.fieldErrors["address"];
if (this.submitError.length > 0) {
this.submitError = "";
}
}

public get isValid(): boolean {
return Object.keys(this.fieldErrors).length === 0;
}
Expand Down Expand Up @@ -199,7 +213,8 @@ export class RegisterViewModel {
this.firstName,
this.lastName,
this.email,
this.telephone
this.telephone,
this.address
);
this.isSubmitting = false;
if (result.success) {
Expand Down
Loading

0 comments on commit 4442e59

Please sign in to comment.