|
21 | 21 | <PropertyColumn Property="x => x.IsVerified" Title="Verified" Editable="false" /> |
22 | 22 | <TemplateColumn Title="Actions" Editable="false"> |
23 | 23 | <CellTemplate> |
24 | | - <MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Edit" OnClick="@context.Actions.StartEditingItemAsync" /> |
25 | | - <MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Delete" OnClick="@(() => DeleteIdentifier(context.Item.Id))" /> |
| 24 | + <MudStack Style="min-width: 120px" Row="true" Spacing="2" Wrap="Wrap.Wrap"> |
| 25 | + <MudTooltip Text="Edit" Color="Color.Primary" Delay="300"> |
| 26 | + <MudIconButton Color="Color.Primary" Variant="Variant.Filled" Icon="@Icons.Material.Filled.Edit" OnClick="@context.Actions.StartEditingItemAsync" /> |
| 27 | + </MudTooltip> |
| 28 | + @if (context.Item.IsPrimary) |
| 29 | + { |
| 30 | + <MudTooltip Text="Unset Primary" Color="Color.Primary" Delay="300"> |
| 31 | + <MudIconButton Color="Color.Primary" Variant="Variant.Filled" Icon="@Icons.Material.Filled.KeyOff" OnClick="@(() => UnsetPrimaryAsync(context.Item.Id))" /> |
| 32 | + </MudTooltip> |
| 33 | + } |
| 34 | + else |
| 35 | + { |
| 36 | + <MudTooltip Text="Set Primary" Color="Color.Primary" Delay="300"> |
| 37 | + <MudIconButton Color="Color.Primary" Variant="Variant.Filled" Icon="@Icons.Material.Filled.Key" OnClick="@(() => SetPrimaryAsync(context.Item.Id))" /> |
| 38 | + </MudTooltip> |
| 39 | + } |
| 40 | + |
| 41 | + <MudTooltip Text="Verify" Color="Color.Primary" Delay="300"> |
| 42 | + <MudIconButton Color="Color.Primary" Variant="Variant.Filled" Icon="@Icons.Material.Filled.Verified" OnClick="@(() => VerifyAsync(context.Item.Id))" /> |
| 43 | + </MudTooltip> |
| 44 | + |
| 45 | + <MudTooltip Text="Delete" Color="Color.Error" Delay="300"> |
| 46 | + <MudIconButton Color="Color.Error" Variant="Variant.Filled" Icon="@Icons.Material.Filled.Delete" OnClick="@(() => DeleteIdentifier(context.Item.Id))" /> |
| 47 | + </MudTooltip> |
| 48 | + </MudStack> |
26 | 49 | </CellTemplate> |
27 | 50 | </TemplateColumn> |
28 | 51 | </Columns> |
|
67 | 90 |
|
68 | 91 | if (firstRender) |
69 | 92 | { |
70 | | - var result = await UAuthClient.Identifiers.GetUserIdentifiersAsync(AuthState.Identity!.UserKey); |
| 93 | + var result = await UAuthClient.Identifiers.GetMyIdentifiersAsync(); |
71 | 94 | if (result != null && result.IsSuccess && result.Value != null) |
72 | 95 | { |
73 | 96 | _identifiers = result.Value.ToList(); |
|
114 | 137 | if (result.IsSuccess) |
115 | 138 | { |
116 | 139 | Snackbar.Add("Identifier added successfully", Severity.Success); |
117 | | - var getResult = await UAuthClient.Identifiers.GetUserIdentifiersAsync(AuthState.Identity!.UserKey); |
| 140 | + var getResult = await UAuthClient.Identifiers.GetMyIdentifiersAsync(); |
118 | 141 | _identifiers = getResult.Value?.ToList() ?? new List<UserIdentifierDto>(); |
119 | 142 | StateHasChanged(); |
120 | 143 | } |
|
124 | 147 | } |
125 | 148 | } |
126 | 149 |
|
| 150 | + private async Task SetPrimaryAsync(Guid id) |
| 151 | + { |
| 152 | + SetPrimaryUserIdentifierRequest request = new() { IdentifierId = id }; |
| 153 | + var result = await UAuthClient.Identifiers.SetPrimarySelfAsync(request); |
| 154 | + if (result.IsSuccess) |
| 155 | + { |
| 156 | + Snackbar.Add("Primary identifier set successfully", Severity.Success); |
| 157 | + var getResult = await UAuthClient.Identifiers.GetMyIdentifiersAsync(); |
| 158 | + _identifiers = getResult.Value?.ToList() ?? new List<UserIdentifierDto>(); |
| 159 | + StateHasChanged(); |
| 160 | + } |
| 161 | + else |
| 162 | + { |
| 163 | + Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Failed to set primary identifier", Severity.Error); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + private async Task VerifyAsync(Guid id) |
| 168 | + { |
| 169 | + VerifyUserIdentifierRequest request = new() { IdentifierId = id }; |
| 170 | + var result = await UAuthClient.Identifiers.VerifySelfAsync(request); |
| 171 | + if (result.IsSuccess) |
| 172 | + { |
| 173 | + Snackbar.Add("Primary identifier verified successfully", Severity.Success); |
| 174 | + var getResult = await UAuthClient.Identifiers.GetMyIdentifiersAsync(); |
| 175 | + _identifiers = getResult.Value?.ToList() ?? new List<UserIdentifierDto>(); |
| 176 | + StateHasChanged(); |
| 177 | + } |
| 178 | + else |
| 179 | + { |
| 180 | + Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Failed to verify primary identifier", Severity.Error); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + private async Task UnsetPrimaryAsync(Guid id) |
| 185 | + { |
| 186 | + UnsetPrimaryUserIdentifierRequest request = new() { IdentifierId = id }; |
| 187 | + var result = await UAuthClient.Identifiers.UnsetPrimarySelfAsync(request); |
| 188 | + if (result.IsSuccess) |
| 189 | + { |
| 190 | + Snackbar.Add("Primary identifier unset successfully", Severity.Success); |
| 191 | + var getResult = await UAuthClient.Identifiers.GetMyIdentifiersAsync(); |
| 192 | + _identifiers = getResult.Value?.ToList() ?? new List<UserIdentifierDto>(); |
| 193 | + StateHasChanged(); |
| 194 | + } |
| 195 | + else |
| 196 | + { |
| 197 | + Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Failed to unset primary identifier", Severity.Error); |
| 198 | + } |
| 199 | + } |
| 200 | + |
127 | 201 | private async Task DeleteIdentifier(Guid id) |
128 | 202 | { |
129 | 203 | DeleteUserIdentifierRequest request = new() { IdentifierId = id }; |
130 | 204 | var result = await UAuthClient.Identifiers.DeleteSelfAsync(request); |
131 | 205 | if (result.IsSuccess) |
132 | 206 | { |
133 | 207 | Snackbar.Add("Identifier deleted successfully", Severity.Success); |
134 | | - var getResult = await UAuthClient.Identifiers.GetUserIdentifiersAsync(AuthState.Identity!.UserKey); |
| 208 | + var getResult = await UAuthClient.Identifiers.GetMyIdentifiersAsync(); |
135 | 209 | _identifiers = getResult.Value?.ToList() ?? new List<UserIdentifierDto>(); |
136 | 210 | StateHasChanged(); |
137 | 211 | } |
138 | 212 | else |
139 | 213 | { |
140 | | - Snackbar.Add("Failed to delete identifier", Severity.Error); |
| 214 | + Snackbar.Add(result?.Problem?.Detail ?? result?.Problem?.Title ?? "Failed to delete identifier", Severity.Error); |
141 | 215 | } |
142 | 216 | } |
143 | 217 |
|
|
0 commit comments